[program-java] Re: Debugging why my code is not running

  • From: "Corbett, James" <James.Corbett@xxxxxxxxxxxxx>
  • To: "'program-java@xxxxxxxxxxxxx'" <program-java@xxxxxxxxxxxxx>
  • Date: Mon, 14 Feb 2011 08:44:41 -0500

Pranav:

Did you select Java Application from that initial list? If not do so and press 
enter. A dialogue will appear and you have the option to set the name of the 
run property. Next tab to the "Main" tabl and continue to tab until you locate 
the edit field for setting the main. ...as in a previous message I indicated 
that I like to use main.Main for the sake of brevity. If not then use 
package_name.class_with_main_name.

Then select the Run or Ok button. This now becomes the default and you can 
either run it with alt + r + r or ctrl + PF11.

Jim


James M. Corbett

Programmer / Analyst |
Canada Revenue Agency | Agence du revenue du Canada
875 Heron Rd.
Ottawa, On.
K1A0L5

James.Corbett@xxxxxxxxxxxxx
Telephone | Téléphone: (613) 941-1338
Facsimile | Télécopieur: (613) 941-2261

Government of Canada | Gouvernement du Canada

E = MC²

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Pranav Lal
Sent: February 12, 2011 04:55
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Debugging why my code is not running

Hi all,

I have written a program in eclipse. The code compiles without any errors or 
warnings. However, the class does not run. I hit ctrl+f11, I am asked to choose 
whether to run the class as an applet or an application. I choose application 
and get a list of applications I can run. My class is not amongst this list. I 
have tried the console view but it only displays the copy right message of the 
third party component I am using. Where do I look to figure out what is 
happening? I even tried debugging the program but I cannot figure out how to 
walk through the code line-by-line.

I am posting the code below.

Pranav

package VPD;

import java.awt.Rectangle;

import java.io.*;




import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.plot.PlotOrientation;


import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;



import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;


public class VPDDemo {
        private JFreeChart curChart; /*main chart variable*/
        private XYSeries s1;
        private XYSeries s2;

        /*constructer*/
        public VPDDemo()
        {
                curChart=createChart(createDataset());
        }
    private XYDataset createDataset()
    { /*start of method*/
        this.s1=new XYSeries ("Demand");
                this.s2= new XYSeries ("Supply");
                XYSeriesCollection allData = new XYSeriesCollection();;
                allData.addSeries(s1 );
                allData.addSeries(s2);

                s1.add(100,1000);
                s1.add(200,3500);


                s2.add(500,1203);
                s2.add(900,8291);

                return allData;
    } /*end of method*/
        private JFreeChart createChart(XYDataset ds)
        { /*start of method*/
                 JFreeChart jc;
                jc=ChartFactory.createXYLineChart("Demand Supply test","Date", 
"Demand and Supply",ds, PlotOrientation.VERTICAL, true, false, false);
        return jc;
        } /*end of method*/

        void exportChartAsSVG(JFreeChart chart, Rectangle bounds, File
svgFile) throws IOException
        {
        // Get a DOMImplementation and create an XML document
        DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();
        Document document = domImpl.createDocument(null, "svg", null);

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        // draw the chart in the SVG generator
        chart.draw(svgGenerator, bounds);

        // Write svg file
        OutputStream outputStream = new FileOutputStream(svgFile);
        Writer out = new OutputStreamWriter(outputStream, "UTF-8");
        svgGenerator.stream(out, true /* use css */);

        outputStream.flush();
        outputStream.close();
        }

        /**
         * @param args
         */
        public void main(String[] args) {
                //

                File svgFile = new File("ViewPlusBATIKTest.svg");
        Rectangle rt=new Rectangle(50,50,800,800);
        // write it to file
        try {
                        exportChartAsSVG(curChart,rt, svgFile);

                //
                System.out.println("Figured saved as " + 
svgFile.getAbsolutePath());

        } catch (IOException e) {
                        System.err.println("Error saving file:\n" + 
e.getMessage());
                }

        }


} /*end of class*/



Other related posts: