permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes JTabbedPane.setTitleAt not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTabbedPane.setTitleAt not working" Watch "JTabbedPane.setTitleAt not working" New topic
Author

JTabbedPane.setTitleAt not working

Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

I've got a small method which I want to iterate through a JTabbedPane and String [] to set the title:



However, with this I get the error NullPointerException:



Line 43 is the tabbedPane.setTitleAt - the tabbedPane is there and it has 11 tabs - so why would I get NullPointerException?
TIA
Adam
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Post a SSCCE.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

The exception ends at that line, so that means that on that line something before a . or array access is null. There is only one culprit: tabbedPane.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

Thanks.

tabbedPane has an instance which has tabs - am I thinking that this doesn't work correctly? This is how I set the constructor up:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Adam Cripps wrote:

That's an often made error. You did not initialize your instance variable but have instead created a local variable that shadows the instance field. This local variable is initialized. Simply remove the type declaration of that local variable and you will use the instance variable instead.
Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

The proverbial "D'Oh!" - many thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTabbedPane.setTitleAt not working