From another class I can call a method to add to the array which works fine.

My method to get a value from an array is:

Code :

public int getValue(int col, int row){
return myArray[col][row];
}

I can call it in that class and it works fine (returns correct int), but from another class I always get a null pointer exception. All other methods work from another class (ie to set a value in the array). Why cant I return the value?

int Number = class.getValue(); -- null pointer.

April 22nd, 2011, 02:53 PM

KevinWorkman

Re: method not working outside of class

Sounds like your reference to "class" is null. Are you sure you're initializing it?

That's just a guess though. If you want more help, you'll have to provide an SSCCE that demonstrates the problem. That doesn't mean you should post your whole program- just the bare essentials.

April 22nd, 2011, 03:53 PM

Scotty

Re: method not working outside of class

I can use other methods, for example

Code :

state.setArray(2);

Which puts a value in row 2 and then prints the array. These work fine.
It is definitely initialised. I cannot post code.