Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer exception woes

 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read about this in the book I'm working through and I'm not sure what I'm doing wrong.

I declare the ArrayList such


and then iterate through it with new object references:

Yet, when I try and iterate through all the objects later on in a different method, I get NullPointerException.


getItems is thus:


What am I doing wrong?
TIA
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the NullPointerException occuring? It should tell you what line causes the exception. So which line is it? If you are not sure how to figure it out, post the entire exception output here and we will show you how to figure out the bad line...

p.s. For other folks, I would appreciate it if noone points it out to the OP yet. I think the OP needs to learn to read his exceptions.
 
Winston Gutkowski
Bartender
Pie
Posts: 10226
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Cripps wrote:What am I doing wrong?

You're not describing how you magically get from an array to a tabbed pane (which, I assume, is a JTabbedPane).

Winston
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:Where is the NullPointerException occuring? It should tell you what line causes the exception. So which line is it? If you are not sure how to figure it out, post the entire exception output here and we will show you how to figure out the bad line...

p.s. For other folks, I would appreciate it if noone points it out to the OP yet. I think the OP needs to learn to read his exceptions.


I'm getting it on line 8 of (which I must admit is the first time I've used a StringBuffer in anger). I checked the API where StringBuffer has a constructor that accepts a string. Does my receiving string called "text" also have to be an Array?

@Steve Luke - I've got my own class that extends JTabbedPane - which has a lot of the CurriculumSubject object instances in it.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Cripps wrote:
Steve Luke wrote:Where is the NullPointerException occuring? It should tell you what line causes the exception. So which line is it? If you are not sure how to figure it out, post the entire exception output here and we will show you how to figure out the bad line...

p.s. For other folks, I would appreciate it if noone points it out to the OP yet. I think the OP needs to learn to read his exceptions.


I'm getting it on line 8 of (which I must admit is the first time I've used a StringBuffer in anger). I checked the API where StringBuffer has a constructor that accepts a string. Does my receiving string called "text" also have to be an Array?


No, text does not need to be an array. Note on line 8 that you are calling the append() method, not the constructor. As a hint: where DO you call the StringBuffer's constructor?
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
Adam Cripps wrote:
Steve Luke wrote:Where is the NullPointerException occuring? It should tell you what line causes the exception. So which line is it? If you are not sure how to figure it out, post the entire exception output here and we will show you how to figure out the bad line...

p.s. For other folks, I would appreciate it if noone points it out to the OP yet. I think the OP needs to learn to read his exceptions.


I'm getting it on line 8 of (which I must admit is the first time I've used a StringBuffer in anger). I checked the API where StringBuffer has a constructor that accepts a string. Does my receiving string called "text" also have to be an Array?


No, text does not need to be an array. Note on line 8 that you are calling the append() method, not the constructor. As a hint: where DO you call the StringBuffer's constructor?


Slap forehead! Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic