问题描述
当我在EditText中输入内容时,我的应用程序不断崩溃,但这种情况在某些情况下不会发生。我正在三星Galaxy Tab 2 10.1 WiFI上运行我的应用程序。 3G(GT-P5100)与Android 4.0.4(ICS)。我使用股票键盘。
My application keeps crashing when I type something in a EditText, but this does not happen always only in some cases. I am running my app on a Samsung Galaxy Tab 2 10.1 WiFI & 3G (GT-P5100) with Android 4.0.4 (ICS). I use the stock Keyboard.
这是我的logcat:
This is my logcat:
11-28 21:43:01.007: E/AndroidRuntime(15540): java.lang.IllegalStateException: focus search returned a view that wasn't able to take focus!
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.widget.TextView.onKeyUp(TextView.java:5833)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.KeyEvent.dispatch(KeyEvent.java:2659)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.View.dispatchKeyEvent(View.java:5547)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
11-28 21:43:01.007: E/AndroidRuntime(15540): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2027)
11-28 21:43:01.007: E/AndroidRuntime(15540): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1388)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
11-28 21:43:01.007: E/AndroidRuntime(15540): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1954)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3360)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2618)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.os.Looper.loop(Looper.java:137)
11-28 21:43:01.007: E/AndroidRuntime(15540): at android.app.ActivityThread.main(ActivityThread.java:4514)
11-28 21:43:01.007: E/AndroidRuntime(15540): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 21:43:01.007: E/AndroidRuntime(15540): at java.lang.reflect.Method.invoke(Method.java:511)
11-28 21:43:01.007: E/AndroidRuntime(15540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
11-28 21:43:01.007: E/AndroidRuntime(15540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
11-28 21:43:01.007: E/AndroidRuntime(15540): at dalvik.system.NativeStart.main(Native Method)
这是我的一个EditTexts:
This is my one of my EditTexts:
<EditText
android:id="@+id/input_ftu_position_other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="64dp"
android:ems="20"
android:inputType="text" />
推荐答案
我遇到了同样的崩溃,尽管它并没有听起来像确切的情况,也许这仍然会有所帮助:
I was having this same crash and although it doesn't sound like the exact situation, perhaps this will still be helpful:
我有两个EditText框。最下面一个是前一个下一个焦点。在某些情况下我会隐藏底部的盒子,所以当我从顶部盒子敲击键盘的下一个时,它会尝试去底部,但是因为它被隐藏会崩溃。我通过将底部框(另一个EditText的Next Down Focus的目标)设置为不可聚焦来修复此问题:
I had two EditText boxes. The bottom one was the Next Focus Down of the top one. In some situations I would hide the bottom box, so when I hit next on the keyboard from the top box, it would try to go the bottom one, but would crash since it was hidden. I fixed this by setting the bottom box (the target of another EditText's Next Down Focus) as not focusable:
EditText inputBox = (EditText)findViewById(R.id.Bottom_Box);
inputBox.setFocusable(false);
我希望这有帮助。
这篇关于致命崩溃:焦点搜索返回了无法获得焦点的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!