我有一个Android应用程序,在不同的布局中有几个edittexts。当我滑动光标时(写点东西,按下书写字符串上的任意位置,然后滑动下面的小标记)或按下/按住标记所有内容时,它们中的每一个似乎都会崩溃我的应用程序。我可以使用swiftkey和原生键盘在两个不同的HTC one(android 5.0.2)上重新创建它。无法使用原生键盘在Samsung Galaxy S6(android 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);
}
}
来自log cat(注意前6行是在崩溃之前发生的 - 它们只是为了完整而包含在内):
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)