单击EditText时出现RuntimeException

单击EditText时出现RuntimeException

本文介绍了单击EditText时出现RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发布的Android应用,可以在运行Android 6.0.1的Nexus 5X上流畅运行.以及运行Android 5.0的Samsung 5.

I have a release Android App that goes smooth on a Nexus 5X running Android 6.0.1. and on a Samsung 5 running Android 5.0.

但是,在其他设备上,双击长按任何EditText会出现奇怪的异常.

However, on other devices weird exceptions rise when double clicking or long clicking any EditText.

这是Alcatel OneTouch (Android 5.1)上的音轨:

E/AndroidRuntime: FATAL EXCEPTION: main
                                   Process: es.solbyte.ociohoteles, PID: 18176
                                                   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:3047)
                                                       at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2302)
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3019)
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3019)
                                                       at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3422)
                                                       at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3672)
                                                       at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3929)
                                                       at android.widget.Editor.performLongClick(Editor.java:900)
                                                       at android.widget.TextView.performLongClick(TextView.java:9104)
                                                       at android.view.View$CheckForLongPress.run(View.java:20236)
                                                       at android.os.Handler.handleCallback(Handler.java:815)
                                                       at android.os.Handler.dispatchMessage(Handler.java:104)
                                                       at android.os.Looper.loop(Looper.java:194)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5631)
                                                       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:959)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
                                                    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=1570
                                                       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:1003)
                                                       at android.content.res.TypedArray.getString(TypedArray.java:188)
                                                       at android.widget.TextView.<init>(TextView.java:1042)
                                                       at android.widget.TextView.<init>(TextView.java:660)
                                                       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:980)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
                                                       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:3047) 
                                                       at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2302) 
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3019) 
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:3019) 
                                                       at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3422) 
                                                       at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3672) 
                                                       at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3929) 
                                                       at android.widget.Editor.performLongClick(Editor.java:900) 
                                                       at android.widget.TextView.performLongClick(TextView.java:9104) 
                                                       at android.view.View$CheckForLongPress.run(View.java:20236) 
                                                       at android.os.Handler.handleCallback(Handler.java:815) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:104) 
                                                       at android.os.Looper.loop(Looper.java:194) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5631) 
                                                       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:959) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 

这是ZTE Kis II Max (Android 4.4.2)上的音轨:

06-29 16:37:44.361 12852-12852/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: es.solbyte.ociohoteles, PID: 12852
                                                   android.view.InflateException: Binary XML file line #17: Error inflating class TextView
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                       at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:2973)
                                                       at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2268)
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2946)
                                                       at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2946)
                                                       at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3166)
                                                       at android.widget.Editor$SelectionModifierCursorController.initHandles(Editor.java:3690)
                                                       at android.widget.Editor$SelectionModifierCursorController.show(Editor.java:3661)
                                                       at android.widget.Editor$SelectionActionModeCallback.onCreateActionMode(Editor.java:2896)
                                                       at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onCreateActionMode(PhoneWindow.java:2811)
                                                       at android.support.v7.view.SupportActionModeWrapper$CallbackWrapper.onCreateActionMode(SupportActionModeWrapper.java:155)
                                                       at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onCreateActionMode(AppCompatDelegateImplV7.java:1742)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionModeFromWindow(AppCompatDelegateImplV7.java:802)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionMode(AppCompatDelegateImplV7.java:696)
                                                       at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.startAsSupportActionMode(AppCompatDelegateImplV14.java:187)
                                                       at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.onWindowStartingActionMode(AppCompatDelegateImplV14.java:171)
                                                       at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2432)
                                                       at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2419)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:689)
                                                       at android.view.View.startActionMode(View.java:4561)
                                                       at android.widget.Editor.startSelectionActionMode(Editor.java:1584)
                                                       at android.widget.Editor.performLongClick(Editor.java:877)
                                                       at android.widget.TextView.performLongClick(TextView.java:8585)
                                                       at android.view.View$CheckForLongPress.run(View.java:18768)
                                                       at android.os.Handler.handleCallback(Handler.java:808)
                                                       at android.os.Handler.dispatchMessage(Handler.java:103)
                                                       at android.os.Looper.loop(Looper.java:193)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5299)
                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:515)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
                                                       at dalvik.system.NativeStart.main(Native Method)
                                                    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=1570
                                                       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:721)
                                                       at android.content.res.TypedArray.getString(TypedArray.java:125)
                                                       at android.widget.TextView.<init>(TextView.java:1002)
                                                       at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
                                                    at android.support.v7.

有人可以解释这是怎么回事吗?它与硬件/发行版有某种联系吗?

Is someone able to explain what is this happening? Is it somehow related with the hardware/distribution?

请考虑到这是一个很大的应用程序,所以我不能在所有崩溃的地方发布它.这是应用程序崩溃的第一个EditText的摘录.

Please take into account that this is a big app so I cannot post all places where it is crashing. This is an extract of the very first EditText where the app is crashing.

// LoginActivity.java
public class LoginActivity extends ApiActivity implements
    onLoginSuccessListener {

    @Bind(R.id.login_field_email)
    protected EditText user;

    /* OnCreate and other methods... */

    @OnTextChanged({R.id.login_field_email, R.id.login_field_password})
    public void onAnyFieldChanged() {
        loginButton.setEnabled(areFieldFilled());
    }

这是内容布局XML文件:

This is the content layout XML file:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".activity.LoginActivity"
    tools:showIn="@layout/activity_login">

    <LinearLayout
        android:id="@+id/login_forms"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_brand"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@android:color/white">

            <EditText
                android:id="@+id/login_field_email"
                style="@style/EditTextLogin"
                android:hint="@string/registration_email"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout>
                ...
        </android.support.design.widget.TextInputLayout>

    </LinearLayout>

    <Button
        ...
    />

</RelativeLayout>

styles.xml:

    <style name="EditTextLogin" parent="android:Widget.EditText">
        <item name="android:fontFamily">sans</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:singleLine">true</item>
        <item name="android:maxLines">1</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">44dp</item>
    </style>

build.gradle文件:

应用插件:"com.android.application"应用插件:"io.fabric"应用插件:"realm-android"

apply plugin: 'com.android.application'apply plugin: 'io.fabric'apply plugin: 'realm-android'

android {

    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "..."
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    signingConfigs {
        config {
            keyAlias '...'
            keyPassword '...'
            storeFile file('...')
            storePassword '...'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            debuggable true
            useProguard false
            applicationIdSuffix ".debug"
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://clojars.org/repo/" }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.0.2'
    compile 'com.google.android.gms:play-services-location:9.0.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton:butterknife:7.0.1'
}

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="es.solbyte.ociohoteles">

    <!-- All needed permissions here -->

    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="false"
        android:theme="@style/Base.AppTheme">

        <!-- Login -->
        <activity
            android:name=".activity.LoginActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/Base.AppTheme.Login"/>

    </application>
<manifest>

以防万一BaseApp主题:

And just in case the BaseApp theme:

<!-- Base -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Colours -->
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColor_dark</item>
    <item name="colorAccent">@color/accentColor</item>
    <item name="android:windowBackground">@color/background_activity</item>
    <!-- Fonts -->
    <item name="android:fontFamily">sans-serif</item>
</style>

推荐答案

editText有相同的问题就我而言,问题出在我的风格上

I have same problem with editTextthe problem in my case was in my style

        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="android:fontFamily" tools:targetApi="jelly_bean">sans-serif</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
    </style>

我的问题通过删除此行代码解决了

my problem solved by removing this line of code

<item name="android:fontFamily" tools:targetApi="jelly_bean">sans-serif</item>

这篇关于单击EditText时出现RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:36