Hey all.

I have a deadline tomorrow, and this thing is killing me, so I come to you with hopes of help.

I have a couple of classes. An info class, which converts a string to ints and puts it in the values array. Another class (plotter), is supposed to read this array, and do stuff with images, based on the ints in the array. My info class actually prints out the ints in the array and all is fine, but whenever I call the array in the plotter class, it returns a nullpointer. The array is public, and should be exposed to all classes. Anyways, here is the info class:

import java.io.*;
import java.util.Scanner;
import java.util.Arrays.*;


public class info {
	public String input;
	public int[] values;
		
		public info() throws IOException {
		    //System.out.print("Reading from file.");
		    StringBuilder text = new StringBuilder();
		    String NL = System.getProperty("line.separator");
		    Scanner scanner = new Scanner(new FileInputStream(Loader.selectedFile1));
		    try {
		      while (scanner.hasNextLine()){
		        text.append(scanner.nextLine() + NL);
		        input = text.toString();
		      }
		    }
		    finally{
		      scanner.close();
		    }
		    for (int i =0; i<1;i++){
		   // System.out.print(input);	
		    }
		    
		   String[] strings= new String[11];
		    strings = input.split(" ");
		    int[] values = new int[11];
		    //System.out.println(strings);
		   
		    
		    try{
		   for (int i = 0; i<strings.length; i++){
			   
			   
	    	values[i]=Integer.parseInt(strings[i]);
		     System.out.println(values[i]);
		      }
		   
		    }
		    catch(NumberFormatException e){
		    	//System.out.println("numberformat exception: " +e.getMessage());	
		    }
		    System.out.println("Value at index 11 is: "+values[10]);
		   plotting();
		  
		    
		    }
		void plotting(){
			 plotter p = new plotter(this);
			
		}
		    
		    }

And here is the plotter class:

import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.*;
import javax.swing.ImageIcon;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;




public class plotter extends JFrame {
	private ImageIcon image0;
	private JLabel label0;
	private ImageIcon image1;
	private JLabel label1;
	private ImageIcon image2;
	private JLabel label2;
	private ImageIcon image3;
	private JLabel label3;
	private ImageIcon image4;
	private JLabel label4;
	private ImageIcon image5;
	private JLabel label5;
	private ImageIcon image6;
	private JLabel label6;
	private ImageIcon image7;
	private JLabel label7;
	private ImageIcon image8;
	private JLabel label8;
	private ImageIcon image9;
	private JLabel label9;
	private ImageIcon image10;
	private JLabel label10;
	public int[] values;
	public info j;
	
	

		
public plotter(info i){
	this.j = i;
	System.out.println("plotter running ");
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	
	
	
	
	setLayout(new FlowLayout());
	

switch (j.values[0]){
case 1: image0 = new ImageIcon("a1.jpg");break;
case 2: image0 = new ImageIcon("a2.jpg");break;
case 3: image0 = new ImageIcon("a3.jpg");break;
case 4: image0 = new ImageIcon("a4.jpg");break;
case 5: image0 = new ImageIcon("a5.jpg");break;

}
	
	label0 = new JLabel(image0);
	add(label0);

this switch structure is repeated 11 times.

The error I'm getting is the following:

java.lang.NullPointerException
	at plotter.<init>(plotter.java:54)
	at info.plotting(info.java:53)
	at info.<init>(info.java:48)
	at Loader$1.actionPerformed(Loader.java:120)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Line 54 in Plotter is: switch (j.values[0]){

Is this because stuff is running concurrently? Because I have absolutely no clue about multithreading, and probably wont be able to resolve this before tomorrow, if threading is required.

Any help is GREATLY appreciated.

Line 30 you create a new array variable rather than using the existing "values". The new variable goes out of scope at the end of that method, leaving the original still null

line30

Thank you guys. This is what happens after very little sleep, you mess up basic stuff.

No i just gotta figure out why it doesnt actually display any images. The GUI is drawn, but no images in there.

again, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.