Lots of users of my program reports "Force Close" on the same error and I can't reproduce the bug so it's hard to debug!
It seems it’s in relation with TabHost (I’ve got two in my application)
For now I’ve tried to extends TabHost overriding dispatchWindowFocusChanged() and testing if getCurrentView() returns null… if so I setCurrentTab() to the last known tab index. But I don’t know if this will do the trick...
Does anyone have any clue about this report?
java.lang.NullPointerException
at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:298)
at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:302)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662开发者_Go百科)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1946)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
And here is the TabHost layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/airport_linear"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
Call setup() before adding tabs if loading TabHost using findViewById(). However: You do not need to call setup() after getTabHost() in TabActivity. http://developer.android.com/reference/android/widget/TabHost.html#setup()
try to extend TabActivity just like
public class TabsExampleActivity extends TabActivity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tabhost_layout);
TabHost tabHost = getTabHost();
...
}
}
I hope this could help
Run into this today on 2.2
be sure you do
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup();
this fixed it.
精彩评论