我有一个安卓应用程序,在不同的布局中有几个edittexts。每一个edittext似乎在我滑动光标(输入一些文字,按下字符串下方的任意位置并滑动小标记)或者按住标记选中全部内容时都会使我的应用程序崩溃。我能够在两个HTC One(安卓5.0.2)上使用Swiftkey和本机键盘重现这种情况,但在三星Galaxy S6(安卓5.1.1)上使用本机键盘时无法重新创建这种情况。我已尝试在没有调试的情况下编译我的应用程序,但情况仍然相同。我尝试在其他应用程序中使用edittexts-它们可以正常工作。
其中一个布局如下:
处理此代码的片段如下所示:
其中一个布局如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/report_message_title"
android:id="@+id/fragment_report_message_title"
android:layout_marginTop="85dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp"
android:labelFor="@+id/fragment_report_message_edit_text"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="150dp"
android:inputType="textMultiLine|textNoSuggestions"
android:ems="10"
android:id="@+id/fragment_report_message_edit_text"
android:layout_below="@+id/fragment_report_message_title"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/report_btn_send"
android:textColor="@color/white"
android:id="@+id/fragment_report_btn_send"
android:layout_below="@+id/fragment_report_message_edit_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"/>
</RelativeLayout>
处理此代码的片段如下所示:
public class ReportFragment extends Fragment {
private View mContentView;
private TextView messageTitle;
public static EditText messageField;
public static Button sendButton;
private OnFragmentInteractionListener mListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContentView = inflater.inflate(R.layout.fragment_report, container, false);
messageField = (EditText) mContentView.findViewById(R.id.fragment_report_message_edit_text);
sendButton = (Button) mContentView.findViewById(R.id.fragment_report_btn_send);
messageTitle = (TextView) mContentView.findViewById(R.id.fragment_report_message_title);
messageTitle.setText(getResources().getString(R.string.report_cancel_message_title));
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = messageField.getText().toString();
if(message.matches("")){
Toast.makeText(getActivity(),"Missing message!",Toast.LENGTH_SHORT).show();
}
else{
onButtonPressed(message);
}
}
});
// Inflate the layout for this fragment
return mContentView;
}
public void onButtonPressed(String message) {
if (mListener != null) {
sendButton.setEnabled(false);
mListener.onSendButtonClicked(message,reportType);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onSendButtonClicked(String message, String reportType);
}
}
从日志中查看(注意,前六行是在崩溃之前发生的 - 它们只是为了完整性而包含在内):
08-25 20:41:31.028 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:31.028 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:31.048 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:31.048 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:31.078 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:31.078 30275-30275/co.listedapp.listed E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-25 20:41:39.877 30275-30275/co.listedapp.listed E/InputEventReceiver﹕ Exception dispatching input event.
08-25 20:41:39.877 30275-30275/co.listedapp.listed E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
08-25 20:41:39.897 30275-30275/co.listedapp.listed E/MessageQueue-JNI﹕ android.view.InflateException: Binary XML file line #17: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:3155)
at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2418)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3555)
at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3896)
at android.widget.Editor$InsertionHandleView.onTouchEvent(Editor.java:4016)
at android.view.View.dispatchTouchEvent(View.java:8444)
at android.view.View.dispatchPointerEvent(View.java:8655)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4094)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5940)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5908)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5872)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6030)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:211)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:153)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=1321
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:967)
at android.content.res.TypedArray.getString(TypedArray.java:176)
at android.widget.TextView.<init>(TextView.java:1030)
at android.widget.TextView.<init>(TextView.java:646)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:44)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:40)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:3155)
at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2418)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3555)
at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3896)
at android.widget.Editor$InsertionHandleView.onTouchEvent(Editor.java:4016)
at android.view.View.dispatchTouchEvent(View.java:8444)
at android.view.View.dispatchPointerEvent(View.java:8655)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4094)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5940)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5908)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5872)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6030)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:211)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:153)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
08-25 20:41:39.897 30275-30275/co.listedapp.listed E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: co.listedapp.listed, PID: 30275
android.view.InflateException: Binary XML file line #17: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:3155)
at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2418)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3555)
at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3896)
at android.widget.Editor$InsertionHandleView.onTouchEvent(Editor.java:4016)
at android.view.View.dispatchTouchEvent(View.java:8444)
at android.view.View.dispatchPointerEvent(View.java:8655)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4094)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5940)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5908)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5872)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6030)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:211)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:153)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=1321
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:967)
at android.content.res.TypedArray.getString(TypedArray.java:176)
at android.widget.TextView.<init>(TextView.java:1030)
at android.widget.TextView.<init>(TextView.java:646)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:44)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:40)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:3155)
at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2418)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3127)
at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3555)
at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3896)
at android.widget.Editor$InsertionHandleView.onTouchEvent(Editor.java:4016)
at android.view.View.dispatchTouchEvent(View.java:8444)
at android.view.View.dispatchPointerEvent(View.java:8655)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4094)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5940)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5908)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5872)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6030)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:211)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:153)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)