我的程序的许多用户报告“强制关闭”相同的错误,但我无法重现该错误,因此很难调试!
看来它与 TabHost 有关(我的应用程序中有两个)
现在,我尝试扩展 TabHost 覆盖dispatchWindowFocusChanged() 并测试 getCurrentView() 是否返回 null…如果是这样,我将 setCurrentTab() 设置为最后一个已知的选项卡索引。
但我不知道这是否能起到作用...
有人对这份报告有任何线索吗?
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)
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)
这是 TabHost 布局:
<?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>
如果使用 findViewById() 加载 TabHost,请在添加选项卡之前调用 setup()。但是:您不需要在 TabActivity 中的 getTabHost() 之后调用 setup()。
http://developer.android.com/reference/android/widget/TabHost.html#setup() http://developer.android.com/reference/android/widget/TabHost.html#setup()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)