gpt4 book ai didi

java - android.view.InflateException : Binary XML file line #91: Binary XML file line #91: Error inflating class

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:17 26 4
gpt4 key购买 nike

这个我的游戏一切正常,除了加载图像作为按钮背景时,我已经尝试了 stackoverflow 中的所有答案,但没有一个有效,当未设置背景图像时,错误消失。以下是我的代码

Logcat

 10-30 19:38:42.473 17302-17302/com.danaraddi.quickmath W/art: Throwing OutOfMemoryError "Failed to allocate a 16777228 byte allocation with 4194304 free bytes and 5MB until OOM"
10-30 19:38:42.473 17302-17302/com.danaraddi.quickmath D/skia: --- allocation failed for scaled bitmap
10-30 19:38:42.476 17302-17302/com.danaraddi.quickmath W/System.err: android.view.InflateException: Binary XML file line #91: Binary XML file line #91: Error inflating class <unknown>
10-30 19:38:42.476 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.Activity.setContentView(Activity.java:2166)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at com.danaraddi.quickmath.activities.ScoreActivity.onCreate(ScoreActivity.java:56)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.Activity.performCreate(Activity.java:6237)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.os.Looper.loop(Looper.java:148)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at java.lang.reflect.Method.invoke(Native Method)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: Caused by: android.view.InflateException: Binary XML file line #91: Error inflating class <unknown>
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.createView(LayoutInflater.java:645)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
10-30 19:38:42.478 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: ... 17 more
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: Caused by: java.lang.reflect.InvocationTargetException
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: at java.lang.reflect.Constructor.newInstance(Native Method)
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.LayoutInflater.createView(LayoutInflater.java:619)
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: ... 26 more
10-30 19:38:42.483 17302-17302/com.danaraddi.quickmath W/System.err: Caused by: java.lang.OutOfMemoryError: Failed to allocate a 16777228 byte allocation with 4194304 free bytes and 5MB until OOM
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.Resources.loadDrawable(Resources.java:2540)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:170)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:115)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1215)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1124)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.Resources.loadDrawableForCookie(Resources.java:2630)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.Resources.loadDrawable(Resources.java:2540)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.view.View.<init>(View.java:3948)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.widget.TextView.<init>(TextView.java:677)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.widget.Button.<init>(Button.java:109)
10-30 19:38:42.484 17302-17302/com.danaraddi.quickmath W/System.err: at android.widget.Button.<init>(Button.java:105)
10-30 19:38:42.485 17302-17302/com.danaraddi.quickmath W/System.err: at android.widget.Button.<init>(Button.java:101)
10-30 19:38:42.485 17302-17302/com.danaraddi.quickmath W/System.err: ... 28 more
10-30 19:38:42.531 17302-17317/com.danaraddi.quickmath W/EGL_emulation: eglSurfaceAttrib not implemented
10-30 19:38:42.531 17302-17317/com.danaraddi.quickmath W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9fbbf0e0, error=EGL_SUCCESS
10-30 19:38:42.728 17302-17317/com.danaraddi.quickmath W/EGL_emulation: eglSurfaceAttrib not implemented
10-30 19:38:42.728 17302-17317/com.danaraddi.quickmath W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9fb7b280, error=EGL_SUCCESS
10-30 19:38:43.227 17302-17317/com.danaraddi.quickmath E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9fb75650
10-30 19:38:46.073 17302-17317/com.danaraddi.quickmath E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9fb766f0

布局 XML

<LinearLayout 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:background="@drawable/bg_green"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="4"
tools:context="com.danaraddi.quickmath.activities.ScoreActivity">

<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="GAME OVER"
android:textSize="40sp" />

</LinearLayout>
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:background="@drawable/button_normal"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_score_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SCORE"
android:layout_marginTop="75dp"
android:gravity="center"
android:textSize="25sp"
/>
<TextView
android:id="@+id/tv_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SCORE"
android:gravity="center"
android:layout_below="@+id/tv_score_title"
android:textSize="20sp"
/>
<TextView
android:layout_below="@+id/tv_score"
android:id="@+id/tv_bestscore_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HIGH SCORE"
android:layout_marginTop="35dp"
android:gravity="center"
android:textSize="25sp"
/>
<TextView
android:id="@+id/tv_bestscore"
android:layout_below="@+id/tv_bestscore_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SCORE"
android:gravity="center"
android:textSize="20sp"
/>
</RelativeLayout>

<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content">
<Button
android:textSize="20sp"
android:text="SHARE"
android:background="@drawable/button"
android:layout_width="100dp"
android:layout_height="50dp" />
</LinearLayout>

<LinearLayout
android:layout_weight=".5"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_return_home"
android:layout_margin="5dp"
android:background="@drawable/btn_home"
android:layout_width="75dp"
android:layout_height="75dp" />

<Button
android:id="@+id/btn_leaderboards"
android:layout_margin="5dp"
android:background="@drawable/btn_game"
android:layout_width="75dp"
android:layout_height="75dp" />

<Button
android:id="@+id/btn_reload"
android:layout_margin="5dp"
android:background="@drawable/btn_reload"
android:layout_width="75dp"
android:layout_height="75dp"

/>
</LinearLayout>
</LinearLayout>

Java 文件

package com.danaraddi.quickmath.activities;



//import com.google.android.gms.games.Games;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.danaraddi.quickmath.GameServices.LeaderBoardHelper;
import com.danaraddi.quickmath.R;
import com.danaraddi.quickmath.Utility.PreferenceManager;
import com.google.android.gms.games.Games;
import com.google.example.games.basegameutils.BaseGameActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

public class ScoreActivity extends BaseGameActivity {
int BACK_KEY_PRESS_COUNT = 0;
PreferenceManager preferenceManager;

// Textview Objects
@InjectView(R.id.tv_score)
TextView tvScore;
@InjectView(R.id.tv_bestscore)
TextView tvBestScore;


@OnClick(R.id.btn_reload)
void btn_reload_click() {
reloadGame();
}


@OnClick(R.id.btn_leaderboards)
void btn_gameservices_click() {
googleGameServices();
}


@OnClick(R.id.btn_return_home)
void btn_home_click() {
returnHome();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// error occuring
try {
setContentView(R.layout.activity_score);
ButterKnife.inject(this);
preferenceManager = new PreferenceManager(this);
setScores();
}catch (Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}

@Override
public void onBackPressed() {
returnHome();
}

// kill activity
private void returnHome(){
this.finish();
}

//reload game
private void reloadGame(){
startActivity(new Intent(this, GameActivity.class));
this.finish();

}

// Game Services
private void googleGameServices(){
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(
getApiClient(), getString(R.string.quick_math_leaderboard)),
2);
}


private void setScores(){
tvScore.setText(String.valueOf( preferenceManager.returnFromPreferenceLong("SCORE")));
tvBestScore.setText(String.valueOf( preferenceManager.returnFromPreferenceLong("HIGHSCORE")));
}

@Override
public void onSignInFailed() {

}

@Override
public void onSignInSucceeded() {
LeaderBoardHelper.submitScore(getApiClient(), preferenceManager.returnFromPreferenceLong("HIGHSCORE"));
}
}

*我已经将背景图片存储在drawable文件夹中,其他用于按钮的图像甚至存储在drawable文件夹中,按钮图像的分辨率为512 * 512px*

<小时/>

I have fixed this issues, i have reduced the image resolution form 512*512 to 96*96 from the guidelines suggested here

*** Button Image size in android

最佳答案

您正在尝试分配 16,777,228 字节的内存块。在许多设备上您不会有那么大的内存块,并且有时您在任何设备上都没有那么大的内存块。

您设置的背景图片太大。根据内存分配,它相当于一个 2048px x 2048px 的方形图像,比我所知道的任何 Android 设备屏幕都大。

您需要降低此背景图像的分辨率,或者为您的背景采用其他解决方案,避免使用位图作为背景图像。

关于java - android.view.InflateException : Binary XML file line #91: Binary XML file line #91: Error inflating class <unknown>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33438145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com