*
The moose likes Beginning Java and the fly likes Java Packets:  java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Packets:  java.lang.NullPointerException" Watch "Java Packets:  java.lang.NullPointerException" New topic
Author

Java Packets: java.lang.NullPointerException

N. Vasilev
Greenhorn

Joined: Mar 23, 2010
Posts: 5
Please see the attachments.
I am sure the mistake is not quite hard to find.
No error messages are appearing. Only when it is run.

Thaks for your help in advance!


[Thumbnail for call_Cat_Sequence.JPG]

[Thumbnail for cat_class.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

When you create an array all of its elements will be null*. Add the following line at the start of your for-loop:
*false for booleans, '\0' for char, 0 for numeric primitives


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
N. Vasilev
Greenhorn

Joined: Mar 23, 2010
Posts: 5
Rob Prime wrote:When you create an array all of its elements will be null*. Add the following line at the start of your for-loop:
*false for booleans, '\0' for char, 0 for numeric primitives


thank you very much...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Welcome to JavaRanch

Please use copy-and paste for all code and error messages; it is much easier to read than JPGs.

When you create a Cat[] array, you create several (in your case 10) memory locations, but each of them points to null. You have to say cats[i] = new Cat( . . .); to put a real Cat in each memory location. Otherwise it will be null and you cannot manipulate a null reference like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Packets: java.lang.NullPointerException