• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null pointer exception woes

 
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic