我发布的Android应用程序在运行Android 6.0.1的Nexus 5X上运行顺畅。以及运行Android 5.0的Samsung 5。
但是,在其他设备上,当双击或长按任意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.
有人能够解释这是怎么回事吗?它与硬件/分发有什么关系吗?
编辑1:
请注意这是一个很棒的应用程序,因此我无法发布崩溃的所有地方。这是应用程序崩溃的第一个EditText的摘录。
// 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文件:
<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' 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主题:
<!-- 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>
答案 0 :(得分:2)
我对editText也有同样的问题 在我的案例中的问题是我的风格
<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>
通过删除这行代码解决了我的问题
<item name="android:fontFamily" tools:targetApi="jelly_bean">sans-serif</item>