长按EditText

时间:2016-04-05 12:32:22

标签: java android xml textview

我有以下EditText:

<EditText
  android:id="@+id/et_username"
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="0.8"
  android:background="#E6E6E6"
  android:gravity="center_vertical"
  android:hint="USERNAME"
  android:paddingRight="5dp"
  android:singleLine="true"
  android:textAppearance="@null"
  android:textColor="#9C9C9C"
  android:textColorHint="#ADADAD"
  android:textSize="20sp"/>

当我将文本粘贴到其中时,我收到以下错误:

FATAL EXCEPTION: main
  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:2928)
      at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2233)
      at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2901)
      at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2901)
      at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3302)
      at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3536)
      at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3780)
      at android.widget.Editor.performLongClick(Editor.java:866)
      at android.widget.TextView.performLongClick(TextView.java:8689)
      at android.view.View$CheckForLongPress.run(View.java:19840)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:135)
      at android.app.ActivityThread.main(ActivityThread.java:5254)
      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:903)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
   Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=389
      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:991)
      at android.content.res.TypedArray.getString(TypedArray.java:176)
      at android.widget.TextView.<init>(TextView.java:1015)
      at android.widget.TextView.<init>(TextView.java:632)
      at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
      at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
      at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
      at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
      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:2928) 
      at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2233) 
      at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2901) 
      at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2901) 
      at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3302) 
      at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3536) 
      at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3780) 
      at android.widget.Editor.performLongClick(Editor.java:866) 
      at android.widget.TextView.performLongClick(TextView.java:8689) 
      at android.view.View$CheckForLongPress.run(View.java:19840) 
      at android.os.Handler.handleCallback(Handler.java:739) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5254) 
      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:903) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

当EditText为空时,它会发生。

此外,textColor属性没有做任何事情,它只适用于textAppearance @null。这种情况发生在所有EditText和TextView中,但不适用于Button。

这与Android Studio或我的项目有关吗?

1 个答案:

答案 0 :(得分:0)

您的问题是您正在尝试复制比editText的maxValue字符串更长的内容

   Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=389

您可以使用android:maxLength="400"或控制您要在那里设置的字符串长度来解决它