This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTabbedPane.setTitleAt not working  RSS feed

 
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post a SSCCE.
 
Sheriff
Posts: 21330
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21330
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The proverbial "D'Oh!" - many thanks.
 
Rob Spoor
Sheriff
Posts: 21330
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!