Quack-Ware.com Free Software & Tutorials

6Aug/112

Some Trouble with Tabs

So while working on my most recent Android project CrowdSource (expect more information about how to download it and what it is later) I decided to implement some tabbing stuff to make the user interface better to deal with. Following a few tutorials online (developer.android.com) and (Custom Android Tabs) I kept encountering a very annoying force close whenever I would select another tab other then my starting one.

08-05 23:03:30.526: ERROR/AndroidRuntime(24650): FATAL EXCEPTION: main
08-05 23:03:30.526: ERROR/AndroidRuntime(24650): java.lang.NullPointerException
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.widget.TabWidget.focusCurrentTab(TabWidget.java:367)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.widget.TabHost.setCurrentTab(TabHost.java:320)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.view.View.performClick(View.java:2408)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.view.View$PerformClick.run(View.java:8816)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.os.Handler.handleCallback(Handler.java:587)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.os.Looper.loop(Looper.java:123)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at java.lang.reflect.Method.invoke(Method.java:521)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-05 23:03:30.526: ERROR/AndroidRuntime(24650):     at dalvik.system.NativeStart.main(Native Method)

After searching for a couple hours for a solution online I found none, and decided to create an entirely new tab project which used the most basic tabs (which of course worked). After adding more and more features a part at a time I found the culprit.

I had the following line

_tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

Which I had added after my lines that added TabSpecs to my TabHost. BIG MISTAKE! This ended up causing the crash and causing me many hours of pain. Hopefully if anyone else is experiencing this crash they will find my post and not have to search their code for an answer.

Comments (2) Trackbacks (0)
  1. Thanks Friend, it helped though I burnt my a** for couple of hours figuring out this problem. Thanks again =D

  2. You are my hero! Had exactly the same issue, and your fix worked flawlessly :)


Leave a comment

(required)

No trackbacks yet.