Solved

JFreeChart no source attached

Posted on 2006-10-26
19
602 Views
Last Modified: 2008-01-09
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/org/jfree.
0
Comment
Question by:blarouche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 6
19 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 17812870
Put it in the /ext directory rather.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17812881
That would be C:\Program Files\Java\jre1.5.0_09\lib\ext  for me.

;JOOP!
0
 

Author Comment

by:blarouche
ID: 17812976
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/org/jfree also ?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 24

Expert Comment

by:sciuriware
ID: 17813126
No, on second thoughts, I think you make a wrong call from your application.
Otherwise you would not have a nullpointer exception.

;JOOP!
0
 

Author Comment

by:blarouche
ID: 17813251
Here is the exact error message

Exception in tread "main" java.lang.NullPointerException
      at org.jfree.data.xy.DefaultHighLowDataset.getX(DefaultHighLowDataset.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


0
 

Author Comment

by:blarouche
ID: 17813275
Here is my console :

Exception in thread "main" java.lang.NullPointerException
      at org.jfree.data.xy.DefaultHighLowDataset.getX(DefaultHighLowDataset.java:131)
      at org.jfree.data.xy.AbstractXYDataset.getXValue(AbstractXYDataset.java:77)
      at org.jfree.data.general.DatasetUtilities.iterateDomainBounds(DatasetUtilities.java:699)
      at org.jfree.data.general.DatasetUtilities.findDomainBounds(DatasetUtilities.java:644)
      at org.jfree.chart.renderer.xy.AbstractXYItemRenderer.findDomainBounds(AbstractXYItemRenderer.java:617)
      at org.jfree.chart.plot.XYPlot.getDataRange(XYPlot.java:3185)
      at org.jfree.chart.axis.DateAxis.autoAdjustRange(DateAxis.java:1190)
      at org.jfree.chart.axis.DateAxis.configure(DateAxis.java:604)
      at org.jfree.chart.axis.Axis.setPlot(Axis.java:823)
      at org.jfree.chart.plot.XYPlot.<init>(XYPlot.java:503)
      at org.jfree.chart.ChartFactory.createHighLowChart(ChartFactory.java:1690)
      at graph.HighLowChartDemo.execute(HighLowChartDemo.java:116)
      at graph.HighLowChartDemo.<init>(HighLowChartDemo.java:53)
      at graph.HighLowChartDemo.main(HighLowChartDemo.java:134)
0
 
LVL 3

Expert Comment

by:KnightFire
ID: 17813553
Can you post the code fragment for your main method?
0
 

Author Comment

by:blarouche
ID: 17813701
  public static void main(final String[] args) {

    final HighLowChartDemo chart = new HighLowChartDemo("eurodollars","High Low Chart");
    chart.execute();
    chart.pack();
    RefineryUtilities.centerFrameOnScreen(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("Chart for "+symbol,d,high,low,open,close,volume);
final JFreeChart chart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);

final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);      

pointer.closeDB();
}
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 17814170
No source attached: means you don't have the sources of Freechart available.

That's not the error.


;JOOP!
0
 

Author Comment

by:blarouche
ID: 17818713
Anybody can help me
0
 

Author Comment

by:blarouche
ID: 17819587
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.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);

final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);    
0
 

Author Comment

by:blarouche
ID: 17819595
I am increasing the point value for this question because I need to solve my problem badly
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17820393
>>>final JFreeChart chart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);

>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
>>>axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
>>>setContentPane(chartPanel);    

Can you give me the line numbers, so we know which line exactly is causing the exception.

;JOOP!
0
 

Author Comment

by:blarouche
ID: 17821331
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.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);

>>>final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
>>>axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
>>>final ChartPanel chartPanel = new ChartPanel(chart);
>>>chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
>>>setContentPane(chartPanel);    




0
 

Author Comment

by:blarouche
ID: 17821358
When I add this line :

final JFreeChart chart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);

Here is the result :

Exception in thread "main" java.lang.NullPointerException
      at org.jfree.data.xy.DefaultHighLowDataset.getX(DefaultHighLowDataset.java:131)
      at org.jfree.data.xy.AbstractXYDataset.getXValue(AbstractXYDataset.java:77)
      at org.jfree.data.general.DatasetUtilities.iterateDomainBounds(DatasetUtilities.java:699)
      at org.jfree.data.general.DatasetUtilities.findDomainBounds(DatasetUtilities.java:644)
      at org.jfree.chart.renderer.xy.AbstractXYItemRenderer.findDomainBounds(AbstractXYItemRenderer.java:617)
      at org.jfree.chart.plot.XYPlot.getDataRange(XYPlot.java:3185)
      at org.jfree.chart.axis.DateAxis.autoAdjustRange(DateAxis.java:1190)
      at org.jfree.chart.axis.DateAxis.configure(DateAxis.java:604)
      at org.jfree.chart.axis.Axis.setPlot(Axis.java:823)
      at org.jfree.chart.plot.XYPlot.<init>(XYPlot.java:503)
      at org.jfree.chart.ChartFactory.createHighLowChart(ChartFactory.java:1690)
      at graph.HighLowChartDemo.execute(HighLowChartDemo.java:113)
      at graph.HighLowChartDemo.main(HighLowChartDemo.java:133)
0
 

Author Comment

by:blarouche
ID: 17821399
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
0
 

Author Comment

by:blarouche
ID: 17821493
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
0
 

Author Comment

by:blarouche
ID: 17825895
Hi experts


This question is still unanswered. Please someone help me

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17842110
? :)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question