做monkey测试时,总碰到一个死机的问题
2515:30:19.010E/AndroidRuntime(2878):Uncaughthandler:thread main exiting due to uncaught exception
09-2515:30:19.026E/AndroidRuntime(2878):java.lang.NullPointerException 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-
可以看出是 TabHost.java 第295行,只在2.1和之前的版本报,找到2.1版本的代码看出
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
mCurrentView.dispatchWindowFocusChanged(hasFocus);//第295行
}
原因找到了,mCurrentView 为空导致的。
在看后续Android版本这块的代码
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
if (mCurrentView != null){
mCurrentView.dispatchWindowFocusChanged(hasFocus);
}
}
说明这个问题可能是系统BUG,在后续已经被修复了
那么只需要自定义一个TabHost类,替换掉应用中的TabHost 即可,就可以避免这种BUG在低版本机器上发生.
public class ESTabHost extends TabHost {
public ESTabHost(Context context) {
super(context);
}
public ESTabHost(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
try {
super.dispatchWindowFocusChanged(hasFocus);
} catch (Exception e) {
}
}
}
2515:30:19.010E/AndroidRuntime(2878):Uncaughthandler:thread main exiting due to uncaught exception
09-2515:30:19.026E/AndroidRuntime(2878):java.lang.NullPointerException 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-2515:30:19.026E/AndroidRuntime(2878):atandroid.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) 09-
可以看出是 TabHost.java 第295行,只在2.1和之前的版本报,找到2.1版本的代码看出
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
mCurrentView.dispatchWindowFocusChanged(hasFocus);//第295行
}
原因找到了,mCurrentView 为空导致的。
在看后续Android版本这块的代码
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
if (mCurrentView != null){
mCurrentView.dispatchWindowFocusChanged(hasFocus);
}
}
说明这个问题可能是系统BUG,在后续已经被修复了
那么只需要自定义一个TabHost类,替换掉应用中的TabHost 即可,就可以避免这种BUG在低版本机器上发生.
public class ESTabHost extends TabHost {
public ESTabHost(Context context) {
super(context);
}
public ESTabHost(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void dispatchWindowFocusChanged(boolean hasFocus) {
try {
super.dispatchWindowFocusChanged(hasFocus);
} catch (Exception e) {
}
}
}