aspose file tools*
The moose likes Beginning Java and the fly likes Access an array, from different class. How? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Access an array, from different class. How?" Watch "Access an array, from different class. How?" New topic
Author

Access an array, from different class. How?

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,

I have two classes





Thank you
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Could you post the stack-trace?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86



Classes name are random by the way
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

The stacktrace says- Nullpointer at Line 17 in B.javain the method legalMove(). Can you show us the actual code? As the one you have mentioned earlier and the stacktrace are not similar.


Mohamed Sanaulla | My Blog
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Ok my apologies. Here is the code


If the row of first clicked button is equal with second or columns then return true and print out, else false

The line 111 in class A just calling this method
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

With the given code- really difficult to tell the reason for the Nullpointer Exception. But either board is NULL or board.getPocketArray(0, 0) is null. You would have to check that. Also check if the instances being referred in the if condition of the legalMove method are not null.

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Ok i tested it with some system.out and...


Nothing printed on the screen

and


Place is NULL printed on Screen.

I cant understand why that place is NULL i have already initialise it. :s
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

I think we would have to look at the code. Can you provide us the complete necessary code to help you resolve this issue?
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Is around 6 classes with super and subclasses my whole programm. Still you want to check it?? I found where the null begining, getArray() method returns null


Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

Did you initialize the individual elements on the array variable? You need to if you haven't.

This


just creates an array object whose elements are null.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That is because you initialized the array but not the array elements. You'll need to iterate through the array and initialize the individual elements.
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hmm...can i have a simple example for this please??
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33



You can extend the same for a 2D array- You will have 2 loops (1 outer loop and 1 Inner loop). Something like this-
>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access an array, from different class. How?