NullPointer exception on XYDataItem.getY()

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
TheHaas
Posts: 21
Joined: Sat Feb 07, 2004 9:14 pm
Contact:

NullPointer exception on XYDataItem.getY()

Post by TheHaas » Wed Feb 11, 2004 8:18 pm

When I do a getY() on a XYDataItem, I get a NullPointException. When doing a trace via Eclipse, I see that the XYDataItem ("point" in the following code) has x equal to an double while y is null. And there are XYSeries in the dataset.

Here is my code:

Code: Select all

		XYSeries tempseries;
		double x,y;
		Double newval;
		XYDataItem point;
		Iterator it;
		List allitems;
		
		for (int i=0; i<dataset.getSeriesCount(); i++) {
			tempseries = dataset.getSeries(i);
			
			allitems = (List) tempseries.getItems();
			it = allitems.iterator();
			while (it.hasNext()) {
				point = (XYDataItem) it.next();
				x = point.getX().doubleValue()+.1;
				System.out.println(x);
				y = point.getY().doubleValue()+0;
				newval = new Double(i+1);
				
				note = new XYTextAnnotation(newval.toString(),x,y);
				plotdata.addAnnotation(note);	
			}
			
				
		}

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 12, 2004 11:44 am

The XYSeries class will allow null Y values, so your code should check for that .
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked