I have a 2d dbl array filled with data, which i can call anywhere within the code:
System.out.println(twodarray[0][0]);
and it works just fine. When i call it as part of Actionlistener it won’t work, and i get a Null pointer exception.
My event listener code:
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == firstbutton)
{
System.out.println(twodarray[0][0]);
}
}
I’m at a loss as to where to start fixing this. The array exists with valid data as shown by the println’s anywhere else in my code. Where am i going wrong here?
You can access the array; that’s not the problem. The problem is that the the array variable is null when the action listener is called. Be sure that you’re not shadowing the array variable inside of a constructor or method. For a more detailed answer, please provide more detail regarding your problem and your code.
In other words are you initializing the class array variable, or are you only initializing an array variable that is local to a method or constructor?