Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText on longPress: ArrayIndexOutOfBoundsException: length=15; index=491

I have this strange behavior I cannot explain. My layout is quite simple: An EditText:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >


        <EditText
            android:id="@+id/etPass"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

</LinearLayout>

When I try to longPress it (to paste some text) I got an imediate Force Close and this error:

05-08 16:56:16.838: E/AndroidRuntime(12164): FATAL EXCEPTION: main
05-08 16:56:16.838: E/AndroidRuntime(12164): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:2995)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2280)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2968)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2968)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3189)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3416)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3652)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.Editor.performLongClick(Editor.java:870)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.TextView.performLongClick(TextView.java:7973)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.View$CheckForLongPress.run(View.java:17140)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.os.Handler.handleCallback(Handler.java:615)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.os.Looper.loop(Looper.java:213)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.app.ActivityThread.main(ActivityThread.java:4786)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at java.lang.reflect.Method.invoke(Method.java:511)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at dalvik.system.NativeStart.main(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164): Caused by: java.lang.reflect.InvocationTargetException
05-08 16:56:16.838: E/AndroidRuntime(12164):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-08 16:56:16.838: E/AndroidRuntime(12164):    ... 25 more
05-08 16:56:16.838: E/AndroidRuntime(12164): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=491
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.content.res.StringBlock.get(StringBlock.java:64)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.content.res.TypedArray.getString(TypedArray.java:124)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.TextView.<init>(TextView.java:800)
05-08 16:56:16.838: E/AndroidRuntime(12164):    at android.widget.TextView.<init>(TextView.java:450)
05-08 16:56:16.838: E/AndroidRuntime(12164):    ... 28 more

I have really no clue what's happening, and I would be pleased to get some help!

Just to be clear, I have nothing in my Activity related to a listener on this EditText:

import android.app.Activity;
import android.os.Bundle;

public class ProActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_pro);

    }

}
like image 208
Waza_Be Avatar asked May 08 '13 15:05

Waza_Be


2 Answers

Just remove this line from your custom style

This single line:

  <item name="android:fontFamily">sans-serif-light</item>

Will make the EditText crash when long pressing it.

The Android copy/paste popup was the root cause of the error.

like image 171
Waza_Be Avatar answered Nov 10 '22 01:11

Waza_Be


this link solved my issue, although the auto-complete in xml files was not working, but the code in this example is correct, i declared all in the same styles file and it worked :

https://github.com/rengwuxian/MaterialEditText/issues/162

and that's what was said in it :

Seems to be an error in styles, verify if you have

<item name="android:fontFamily"></item>

in your application theme, not in the themes view, in application theme. The same error happened to me until i removed this line of my style.xml, if you have that line, remove them, if you need this property, you can stylize textviews and buttons with:

<style name="TextViewStyle" parent="android:Widget.TextView">
    <item name="android:fontFamily">sans-serif-medium</item>
</style>

<style name="ButtonStyle" parent="android:Widget.Holo.Button">
    <item name="android:fontFamily">sans-serif-medium</item>
</style>

And in your app theme, use:

<item name="android:textViewStyle">@style/TextViewStyle</item>
<item name="android:buttonStyle">@style/ButtonStyle</item>
like image 20
Ahmed Adel Ismail Avatar answered Nov 10 '22 01:11

Ahmed Adel Ismail