我花了很长时间寻找这个问题的答案,但似乎无法解决。
当我在调试模式下创建APK时,我通过“ Android Studio”创建的应用运行正常,但是,如果我创建捆绑包并将其上传到Play商店,则会在11台设备(包括我的11台设备)中崩溃完全一样的错误:
问题:java.lang.RuntimeException:无法启动活动ComponentInfo {maxmansung.finaljudgement / maxmansung.finaljudgement.MainScreen}:android.view.InflateException:二进制XML文件行#65:二进制XML文件行65:错误膨胀类按钮
似乎正在发生的事情是该应用由于某种原因根本无法打开任何按钮。我曾尝试在错误点删除按钮,但是它只是变成了另一个按钮的崩溃。
错误日志
FATAL EXCEPTION: main Process: maxmansung.finaljudgement, PID: 20309 java.lang.RuntimeException: Unable to start activity ComponentInfo{maxmansung.finaljudgement/maxmansung.finaljudgement.MainScreen}: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class Button at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6524) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) Caused by: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class Button Caused by: android.view.InflateException: Binary XML file line #65: Error inflating class Button Caused by: java.lang.ArrayIndexOutOfBoundsException: length=58; index=309 at android.content.res.StringBlock.get(StringBlock.java:65) at android.content.res.AssetManager.getPooledStringForCookie(AssetManager.java:642) at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1279) at android.content.res.TypedArray.getString(TypedArray.java:219) at android.widget.TextView.(TextView.java:1157) at android.widget.Button.(Button.java:109) at android.widget.Button.(Button.java:105) at android.support.v7.widget.AppCompatButton.(AppCompatButton.java:71) at android.support.v7.widget.AppCompatButton.(AppCompatButton.java:67) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109) at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738) at android.view.LayoutInflater.rInflate(LayoutInflater.java:869) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at android.view.LayoutInflater.inflate(LayoutInflater.java:377) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at maxmansung.finaljudgement.MainScreen.onCreate(MainScreen.java:24) at android.app.Activity.performCreate(Activity.java:6910) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6524) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
游戏代码
如果我保留OnClickListener
个部分,则崩溃将继续
package maxmansung.finaljudgement;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import maxmansung.finaljudgement.savedVariables.saveSettings;
public class MainScreen extends AppCompatActivity {
@Override
public void onBackPressed() {
System.exit(0);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
saveSettings settings = new saveSettings(this);
settings.updateFromSave(this);
Boolean currentTrue = settings.getCurrentTrue();
Button mainScreenNew = findViewById(R.id.mainScreenNew);
Button mainScreenCont = findViewById(R.id.mainScreenCont);
Button mainScreenAchievements = findViewById(R.id.mainScreenAchieve);
if (currentTrue){
mainScreenCont.setVisibility(View.VISIBLE);
} else {
mainScreenCont.setVisibility(View.GONE);
}
if (settings.achievementsGained()){
mainScreenAchievements.setVisibility(View.VISIBLE);
} else {
mainScreenAchievements.setVisibility(View.GONE);
}
final Animation clickAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_click);
mainScreenNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation.AnimationListener listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent gamePage = new Intent(getApplicationContext(),GamePage.class);
gamePage.putExtra("continue", false);
startActivity(gamePage);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
};
clickAnimation.setAnimationListener(listener);
view.startAnimation(clickAnimation);
}
});
XML页面
如果我删除了drawableLeft
和drawableStart
部分,则崩溃将变为看起来完全相同的崩溃,但又回到了XML代码中
我已删除了之前的代码,因为它不会影响崩溃
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="maxmansung.finaljudgement.MainScreen">
<Button
android:id="@+id/mainScreenAchieve"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:drawableStart="@drawable/achievement_icon"
android:drawableLeft="@drawable/achievement_icon"
android:text="@string/mainScreenAchievements"
android:textAllCaps="true"
android:textColor="@color/colorText"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainScreenCont" />
答案 0 :(得分:0)
由于涉及可绘制对象,因此有时会发生此类错误。
我在您的xml中看到此@drawable/achievement_icon
用于ID为Button
的{{1}}。
是否存在这种可绘制对象仅存储在mainScreenAchieve
之类的文件夹中,而不存储在主drawable-v24
文件夹中的情况?
如果是这种情况,则也将其复制并粘贴到主drawable
文件夹中。
否则,在版本较低的设备中,此drawable不可用,这会导致应用崩溃。
答案 1 :(得分:0)
它似乎与text
设置有关。您的strings.xml
是否格式错误?还是某些构建类型缺少它?
还-在此行中有+
:app:layout_constraintTop_toBottomOf="@+id/mainScreenCont"
可能会引起问题。它不需要+
。