我使用Crashlytics获得了一些崩溃日志,其中包含以下堆栈:
Fatal Exception: java.lang.IllegalStateException: focus search returned a view that wasn't able to take focus!
at android.widget.TextView.onKeyUp(TextView.java:6413)
at android.view.KeyEvent.dispatch(KeyEvent.java:2712)
at android.view.View.dispatchKeyEvent(View.java:9960)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:387)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:406)
at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1798)
at android.app.Activity.dispatchKeyEvent(Activity.java:3024)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:320)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4331)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4302)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3999)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4056)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6247)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6221)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6182)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3651)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
我能找到的最接近的答案是:Fatal crash: Focus search returned a view that wasn't able to take focus
但我的问题是,如何跟踪此次崩溃的来源? 很难指出它,因为崩溃日志对于实际崩溃的确切来源
还不够详细答案 0 :(得分:1)
我也使用以下方法解决此问题:
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
只需将其设置为我的editText de ImeOptions。我希望这个对你有用。
答案 1 :(得分:0)
我通过显式提供要返回的EditText的focusSearch方法的值来解决我的项目中的崩溃问题。 (否则,Android会解决它认为自己的下一个可聚焦视图)。子类EditText并提供以下附加代码:
private MyEditText nextFocusField;
@Override
public View focusSearch(@ViewCompat.FocusRealDirection int direction) {
if (direction == FOCUS_DOWN) {
return (View) nextFocusField;
}
return super.focusSearch(direction);
}
public void setNextFocusField(MyEditText nextFocusField) {
this.nextFocusField = nextFocusField;
}
然后在我的片段类中设置EditTexts,我确保为每个字段提供下一个EditText。按照我想要的顺序在ArrayList中收集它们,我按照这样的方式分配它们:
int editTextCount = editTexts.size();
for (int i = 0; i < editTextCount; i++) {
MyEditText editText = (MyEditText) editTexts.get(i);
if (i < editTextCount - 1) { // if not the last item
editText.setNextFocusField((MyEditText) editTexts.get(i + 1));
}
else if (editTextCount > 1) {
editText.setNextFocusField(null);
}
}
答案 2 :(得分:0)
它只是在水平方向发生在我身上, 因为editText占据了所有屏幕,并且自动添加了“下一步”按钮。 当我单击“下一步”时,它使应用程序崩溃了。
解决方案是通过以下方式阻止editText填充整个活动:
android:imeOptions="flagNoExtractUi"