david wrote:
> Hello everyone, I am a new with JAVA and I have one problem now which
> I can not figure out now, maybe I am tired. Let's get to the problem.
> 3 small parts of the code:
>
> Boolean linksVault[][] = null;
> if (!fLoadData(linksVault, args[0])) {
> System.out.println("Kazkas blogai ir tiek");
> System.exit(1);
> }
>
> .........
>
> private static boolean fLoadData(Boolean[][] linksVault, final
> String fName) {
>
> .........
>
> linksVault = new Boolean[countTop][countTop];
>
> So I send linksVault reference to the fLoadData, which then creates
> the matrix of Boolean object it everything is perfect with it inside
> that method, but outside it always get NullPointerException. It looks
> like linksVault does not point to the matrix, any ideas way?
The linksVault in fLoadData is private to fLoadData and
not connected with the linksVault variable in the caller. It
gets an initial value (null, in this case) from the method
call, but nothing fLoadData does to it afterward has any
effect on the caller. When you assign a new value to linksVault
inside fLoadData, nothing happens to the completely independent
linksVault variable in the caller.
Here's another example:
void plusOne(int value) {
value = value + 1;
}
...
int answer = 42;
System.out.println("The Answer is " + answer);
plusOne(answer);
System.out.println("The Answer is " + answer);
Do you expect The Answer to change, just because of the
assignment inside plusOne? If you say "Yes," then consider
System.out.println("The Answer is " + 42);
plusOne(42);
System.out.println("The Answer is " + 42);
--
Eric Sosman
esosman@[EMAIL PROTECTED]


|