This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Null pointer exception woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Null pointer exception woes" Watch "Null pointer exception woes" New topic
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: 4167
    
  21

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: 7551
    
  18

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?
Articles by Winston can be found here
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: 4167
    
  21

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: http://aspose.com/file-tools
 
subject: Null pointer exception woes
 
Similar Threads
JTabbedPane.setTitleAt not working
I want to handle an array of JTextFields to insert in to a TextArea when a given button is pushed.
Blank Frame or Panel
Handling methods for an object that is held in an ArrayList
How to iterate through an Array of objects and a file at the same time?