本文介绍了在显示java.lang.NullPointerException android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:298)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是同样的错误很多我的方案报告强制关闭的用户,我不能重现bug,因此很难调试!

这似乎是与TabHost(我在我的应用程序有两个)

关系

现在我试图延伸TabHost覆盖dispatchWindowFocusChanged()和测试,如果getCurrentView()返回null ......如果让我setCurrentTab()到最后一个已知的选项卡索引。
但我不知道这是否会做的伎俩...

有没有人有此报告的任何线索?

 显示java.lang.NullPointerException
在android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:298)
在android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:302)
在android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
在android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
在android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
在android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
在android.view.ViewRoot.handleMessage(ViewRoot.java:1946)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:123)
在android.app.ActivityThread.main(ActivityThread.java:4627)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:521)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
在dalvik.system.NativeStart.main(本机方法)

这里是TabHost布局:

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  机器人:ID =@ + ID / main_layout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:方向=垂直>
  < TabHost
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_weight =1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <的LinearLayout
      机器人:ID =@ + ID / airport_linear
      机器人:方向=垂直
      机器人:layout_width =FILL_PARENT
      机器人:layout_height =FILL_PARENT>
      < TabWidget
        机器人:ID =@机器人:ID /标签
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT/>
      <的FrameLayout
        机器人:ID =@机器人:ID / tabcontent
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT/>
    < / LinearLayout中>
  < / TabHost>
< / LinearLayout中>


解决方案

在运行2.2变成今天这个

要确保你做

  mTab​​Host =(TabHost)findViewById(R.id.tabhost);
mTabHost.setup();

这固定它。

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)
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>
解决方案

Run into this today on 2.2

be sure you do

mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup();

this fixed it.

这篇关于在显示java.lang.NullPointerException android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:298)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:14