• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Packets: java.lang.NullPointerException

 
N. Vasilev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
call_Cat_Sequence.JPG
[Thumbnail for call_Cat_Sequence.JPG]
cat_class.JPG
[Thumbnail for cat_class.JPG]
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
N. Vasilev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic