| Author |
Null pointer exception woes
|
Adam Cripps
Ranch Hand
Joined: Oct 01, 2011
Posts: 41
|
|
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
Joined: Jan 28, 2003
Posts: 3027
|
|
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.
|
Steve
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4739
|
|
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
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Adam Cripps
Ranch Hand
Joined: Oct 01, 2011
Posts: 41
|
|
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
Joined: Jan 28, 2003
Posts: 3027
|
|
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
Joined: Oct 01, 2011
Posts: 41
|
|
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.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Null pointer exception woes
|
|
|