• 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

java.lang.illegalStateException Actionbar Tab must have a callback

 
Ranch Hand
Posts: 52
1
MySQL Database Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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





 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic