blarouche
asked on
JFreeChart no source attached
Hi Experts,
I am trying to create a chart from a dataset.
Everything is all right, I have no error but when I run the program I have a nullpointer exception no source attached.
I think the problem is with my class path.
I downloaded JFreeChart from SourceForge and I put the jar files into my jre directory.
Is it all I have to do or where do I put the source files jfreechart-1.0.2/source/or g/jfree.
I am trying to create a chart from a dataset.
Everything is all right, I have no error but when I run the program I have a nullpointer exception no source attached.
I think the problem is with my class path.
I downloaded JFreeChart from SourceForge and I put the jar files into my jre directory.
Is it all I have to do or where do I put the source files jfreechart-1.0.2/source/or
That would be C:\Program Files\Java\jre1.5.0_09\lib \ext for me.
;JOOP!
;JOOP!
ASKER
Sorry the jar files have been put exactly there jre1.5.0_09\lib\ext.
Do I have to include the folder jfreechart-1.0.2/source/or g/jfree also ?
Do I have to include the folder jfreechart-1.0.2/source/or
No, on second thoughts, I think you make a wrong call from your application.
Otherwise you would not have a nullpointer exception.
;JOOP!
Otherwise you would not have a nullpointer exception.
;JOOP!
ASKER
Here is the exact error message
Exception in tread "main" java.lang.NullPointerExcep tion
at org.jfree.data.xy.DefaultH ighLowData set.getX(D efaultHigh LowDataset .java:131)
etc....
If I click on the error here is the explanation :
Source not found
The jar file jfreechart-1.0.2.jar has no source attachment.
you can attach the source by clicking Attach Source below
Exception in tread "main" java.lang.NullPointerExcep
at org.jfree.data.xy.DefaultH
etc....
If I click on the error here is the explanation :
Source not found
The jar file jfreechart-1.0.2.jar has no source attachment.
you can attach the source by clicking Attach Source below
ASKER
Here is my console :
Exception in thread "main" java.lang.NullPointerExcep tion
at org.jfree.data.xy.DefaultH ighLowData set.getX(D efaultHigh LowDataset .java:131)
at org.jfree.data.xy.Abstract XYDataset. getXValue( AbstractXY Dataset.ja va:77)
at org.jfree.data.general.Dat asetUtilit ies.iterat eDomainBou nds(Datase tUtilities .java:699)
at org.jfree.data.general.Dat asetUtilit ies.findDo mainBounds (DatasetUt ilities.ja va:644)
at org.jfree.chart.renderer.x y.Abstract XYItemRend erer.findD omainBound s(Abstract XYItemRend erer.java: 617)
at org.jfree.chart.plot.XYPlo t.getDataR ange(XYPlo t.java:318 5)
at org.jfree.chart.axis.DateA xis.autoAd justRange( DateAxis.j ava:1190)
at org.jfree.chart.axis.DateA xis.config ure(DateAx is.java:60 4)
at org.jfree.chart.axis.Axis. setPlot(Ax is.java:82 3)
at org.jfree.chart.plot.XYPlo t.<init>(X YPlot.java :503)
at org.jfree.chart.ChartFacto ry.createH ighLowChar t(ChartFac tory.java: 1690)
at graph.HighLowChartDemo.exe cute(HighL owChartDem o.java:116 )
at graph.HighLowChartDemo.<in it>(HighLo wChartDemo .java:53)
at graph.HighLowChartDemo.mai n(HighLowC hartDemo.j ava:134)
Exception in thread "main" java.lang.NullPointerExcep
at org.jfree.data.xy.DefaultH
at org.jfree.data.xy.Abstract
at org.jfree.data.general.Dat
at org.jfree.data.general.Dat
at org.jfree.chart.renderer.x
at org.jfree.chart.plot.XYPlo
at org.jfree.chart.axis.DateA
at org.jfree.chart.axis.DateA
at org.jfree.chart.axis.Axis.
at org.jfree.chart.plot.XYPlo
at org.jfree.chart.ChartFacto
at graph.HighLowChartDemo.exe
at graph.HighLowChartDemo.<in
at graph.HighLowChartDemo.mai
Can you post the code fragment for your main method?
ASKER
public static void main(final String[] args) {
final HighLowChartDemo chart = new HighLowChartDemo("eurodoll ars","High Low Chart");
chart.execute();
chart.pack();
RefineryUtilities.centerFr ameOnScree n(chart);
chart.setVisible(true);
}
private void execute(){
DBQuotes pointer = new DBQuotes(true);
/**
* Loads Daily Prices
*/
price = getPrices(symbol,pointer);
if (price.getSize()==0){
System.out.println("No quotes founds for symbol "+symbol+", system can't works.");
System.exit(1);
}
high = new double[price.getSize()];
low = new double[price.getSize()];
close = new double[price.getSize()];
open = new double[price.getSize()];
date = new int[price.getSize()];
volume = new double[price.getSize()];
d = new Date[price.getSize()];
for (int i=price.getFirst();i<price .getLast() +1;i++){
high[i] = price.getHigh(i);
//System.out.println(price .getHigh(i ));
low[i] = price.getLow(i);
//System.out.println(price .getLow(i) );
close[i] = price.getClose(i);
//System.out.println(price .getClose( i));
open[i] = price.getOpen(i);
//System.out.println(price .getOpen(i ));
date[i] = price.getDate(i);
//System.out.println(price .getDate(i ));
volume[1] = price.getVolume(i);
try{
DateFormat sdf = new SimpleDateFormat("yyyMMdd" );
d[i] = sdf.parse(Integer.toString (i));
}catch (ParseException e) {
}
}
final DefaultHighLowDataset dataset = new DefaultHighLowDataset("Cha rt for "+symbol,d,high,low,open,c lose,volum e);
final JFreeChart chart = ChartFactory.createHighLow Chart("Hig h-Low-Open -Close Demo","Time", "Value",dataset, true);
final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai nAxis();
axis.setTickMarkPosition(D ateTickMar kPosition. MIDDLE);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSiz e(new java.awt.Dimension(500, 270));
setContentPane(chartPanel) ;
pointer.closeDB();
}
final HighLowChartDemo chart = new HighLowChartDemo("eurodoll
chart.execute();
chart.pack();
RefineryUtilities.centerFr
chart.setVisible(true);
}
private void execute(){
DBQuotes pointer = new DBQuotes(true);
/**
* Loads Daily Prices
*/
price = getPrices(symbol,pointer);
if (price.getSize()==0){
System.out.println("No quotes founds for symbol "+symbol+", system can't works.");
System.exit(1);
}
high = new double[price.getSize()];
low = new double[price.getSize()];
close = new double[price.getSize()];
open = new double[price.getSize()];
date = new int[price.getSize()];
volume = new double[price.getSize()];
d = new Date[price.getSize()];
for (int i=price.getFirst();i<price
high[i] = price.getHigh(i);
//System.out.println(price
low[i] = price.getLow(i);
//System.out.println(price
close[i] = price.getClose(i);
//System.out.println(price
open[i] = price.getOpen(i);
//System.out.println(price
date[i] = price.getDate(i);
//System.out.println(price
volume[1] = price.getVolume(i);
try{
DateFormat sdf = new SimpleDateFormat("yyyMMdd"
d[i] = sdf.parse(Integer.toString
}catch (ParseException e) {
}
}
final DefaultHighLowDataset dataset = new DefaultHighLowDataset("Cha
final JFreeChart chart = ChartFactory.createHighLow
final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai
axis.setTickMarkPosition(D
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSiz
setContentPane(chartPanel)
pointer.closeDB();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Anybody can help me
ASKER
I run the program many times and found out where the bug is.
The bug happens when the program reaches this block :
final JFreeChart chart = ChartFactory.createHighLow Chart("Hig h-Low-Open -Close Demo","Time", "Value",dataset, true);
final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai nAxis();
axis.setTickMarkPosition(D ateTickMar kPosition. MIDDLE);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSiz e(new java.awt.Dimension(500, 270));
setContentPane(chartPanel) ;
The bug happens when the program reaches this block :
final JFreeChart chart = ChartFactory.createHighLow
final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai
axis.setTickMarkPosition(D
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSiz
setContentPane(chartPanel)
ASKER
I am increasing the point value for this question because I need to solve my problem badly
>>>final JFreeChart chart = ChartFactory.createHighLow Chart("Hig h-Low-Open -Close Demo","Time", "Value",dataset, true);
>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai nAxis();
>>>axis.setTickMarkPositio n(DateTick MarkPositi on.MIDDLE) ;
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferred Size(new java.awt.Dimension(500, 270));
>>>setContentPane(chartPan el);
Can you give me the line numbers, so we know which line exactly is causing the exception.
;JOOP!
>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai
>>>axis.setTickMarkPositio
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferred
>>>setContentPane(chartPan
Can you give me the line numbers, so we know which line exactly is causing the exception.
;JOOP!
ASKER
If I delete the following lines the program runs normally without any problems but as you know I have only the frame with no chart.
The problem starts with line final JFreeChart = .......................... .......... .......... .......... .......... ...
>>>final JFreeChart chart = ChartFactory.createHighLow Chart("Hig h-Low-Open -Close Demo","Time", "Value",dataset, true);
>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai nAxis();
>>>axis.setTickMarkPositio n(DateTick MarkPositi on.MIDDLE) ;
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferred Size(new java.awt.Dimension(500, 270));
>>>setContentPane(chartPan el);
The problem starts with line final JFreeChart = ..........................
>>>final JFreeChart chart = ChartFactory.createHighLow
>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomai
>>>axis.setTickMarkPositio
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferred
>>>setContentPane(chartPan
ASKER
When I add this line :
final JFreeChart chart = ChartFactory.createHighLow Chart("Hig h-Low-Open -Close Demo","Time", "Value",dataset, true);
Here is the result :
Exception in thread "main" java.lang.NullPointerExcep tion
at org.jfree.data.xy.DefaultH ighLowData set.getX(D efaultHigh LowDataset .java:131)
at org.jfree.data.xy.Abstract XYDataset. getXValue( AbstractXY Dataset.ja va:77)
at org.jfree.data.general.Dat asetUtilit ies.iterat eDomainBou nds(Datase tUtilities .java:699)
at org.jfree.data.general.Dat asetUtilit ies.findDo mainBounds (DatasetUt ilities.ja va:644)
at org.jfree.chart.renderer.x y.Abstract XYItemRend erer.findD omainBound s(Abstract XYItemRend erer.java: 617)
at org.jfree.chart.plot.XYPlo t.getDataR ange(XYPlo t.java:318 5)
at org.jfree.chart.axis.DateA xis.autoAd justRange( DateAxis.j ava:1190)
at org.jfree.chart.axis.DateA xis.config ure(DateAx is.java:60 4)
at org.jfree.chart.axis.Axis. setPlot(Ax is.java:82 3)
at org.jfree.chart.plot.XYPlo t.<init>(X YPlot.java :503)
at org.jfree.chart.ChartFacto ry.createH ighLowChar t(ChartFac tory.java: 1690)
at graph.HighLowChartDemo.exe cute(HighL owChartDem o.java:113 )
at graph.HighLowChartDemo.mai n(HighLowC hartDemo.j ava:133)
final JFreeChart chart = ChartFactory.createHighLow
Here is the result :
Exception in thread "main" java.lang.NullPointerExcep
at org.jfree.data.xy.DefaultH
at org.jfree.data.xy.Abstract
at org.jfree.data.general.Dat
at org.jfree.data.general.Dat
at org.jfree.chart.renderer.x
at org.jfree.chart.plot.XYPlo
at org.jfree.chart.axis.DateA
at org.jfree.chart.axis.DateA
at org.jfree.chart.axis.Axis.
at org.jfree.chart.plot.XYPlo
at org.jfree.chart.ChartFacto
at graph.HighLowChartDemo.exe
at graph.HighLowChartDemo.mai
ASKER
I think it has something to do with my dataset.
Maybe my dataset is null. I am new to JFreeChart and I am not sure about creating my dataset
Maybe my dataset is null. I am new to JFreeChart and I am not sure about creating my dataset
ASKER
I have solved my problem.
Now I would like to allocate my points. Fortunately I have another question.
I got my chart but I have to resize my Y axis to make it clearer. How do I do that ?
Thank you
Now I would like to allocate my points. Fortunately I have another question.
I got my chart but I have to resize my Y axis to make it clearer. How do I do that ?
Thank you
ASKER
Hi experts
This question is still unanswered. Please someone help me
This question is still unanswered. Please someone help me
? :)
;JOOP!