Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.illegalStateException Actionbar Tab must have a callback

 
Stephen Black
Ranch Hand
Posts: 52
1
Chrome MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after much Goggling and RTFMing I still don't understand how I am supposed to supply a callback in this code so that android will stop throwing an exception at runtime
The error is that Actionbar Tab(s) apparently don't have a callback
Only the code up to line 54 should be applicable?

 
Stephen Black
Ranch Hand
Posts: 52
1
Chrome MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolution
If you notice in lines 2 and 3 (49 and 50 in the original)
I tried to add the tabs to the action bar
and then in lines 5 and 6 (52 and 53 in the original)
I tried to add the listener to the tabs

In this case it actually matters what order you try and do things in
Before you add a tab to the action bar it MUST have a listener added to it
otherwise you will get an exemption at run time

ALSO I placed the code for the NavTabListener class in a more sensible place
I placed it in the main body of the DynamicFragment class rather than placing it in the middle of
the onCreate() method
The Finished Code





 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reporting the solution. It seems indeed unusual that the listeners would have to be added first. Off the top of my head I can't think of other places in the Android API (or the Java API, for that matter) where the listener couldn't be added later.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is good info! I didn't really believe it, I thought it might be your use of commit() and/or addToBackStack() (both of which are handled for you and if you do yourself, the API Guide says, could give exceptions). But looking further, the API for ActionBar.Tab says the order matters. Very strange indeed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic