我在两周内处理我的应用程序,每次按下开始按钮时突然崩溃。 重要的是要提到它在我的主电话(注3)和我的开发者电话(100美元电话)上的崩溃。日志说明了一个XML文件(它是一个弹出窗口)。
以下是日志:
05-14 22:18:40.604 28373-28373/? E/dalvikvm-heap﹕ Out of memory on a 23289136-byte allocation.
05-14 22:18:40.614 28373-28373/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: think.example.com.think, PID: 28373
java.lang.RuntimeException: Unable to start activity ComponentInfo{think.example.com.think/think.example.com.think.FirstQuestion}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
at android.app.ActivityThread.access$800(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at think.example.com.think.FirstQuestion.onCreate(FirstQuestion.java:70)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
at android.app.ActivityThread.access$800(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at think.example.com.think.FirstQuestion.onCreate(FirstQuestion.java:70)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
at android.app.ActivityThread.access$800(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3054)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3694)
at android.view.View.<init>(View.java:3624)
at android.view.ViewGroup.<init>(ViewGroup.java:474)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at think.example.com.think.FirstQuestion.onCreate(FirstQuestion.java:70)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
at android.app.ActivityThread.access$800(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/cluebackground"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="0dp"
android:minWidth="300dp"
android:minHeight="400dp"
>
<ImageButton
android:layout_width="40dp "
android:layout_height="40dp"
android:textStyle="bold"
android:id="@+id/exit"
android:background="@drawable/roundexit"
android:layout_marginTop="50dp"
android:layout_marginLeft="45dp"
android:onClick="exitPopup"
android:layout_gravity="top" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingTop="55dp"
android:paddingRight="50dp"
android:paddingEnd="50dp"
android:focusableInTouchMode="false">
<ImageView
android:layout_width="21dp"
android:layout_height="22dp"
android:background="@drawable/coin"
android:layout_marginTop="6dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textSize="27sp"
android:textColor="#ffffffff"
android:textStyle="bold"
android:id="@+id/clueScore" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:paddingTop="0dp">
<TextView
android:id="@+id/clue"
android:layout_width="290dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="It will cost you 50 coins to get the clue"
android:textSize="27dp"
android:layout_marginBottom="40dp"
android:textColor="#fffefdff"
android:layout_gravity="center"
android:textStyle="bold" />
</LinearLayout>
<Button
android:layout_width="120dp"
android:layout_height="50dp"
android:text="Get clue"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="200dp"
android:background="@drawable/stylepressed"
android:onClick="getClue" />
</RelativeLayout>
我还想提一下,如果我在java'on create'方法中删除与此XML相关的行,它就可以了。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_question);
write = (EditText) findViewById(R.id.writeAnswer);
gameScore = (TextView) findViewById(R.id.gameScore);
//SET POPUP MENU
inflater = (LayoutInflater) FirstQuestion.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.menu, null);
init();
popupInit();
//END OF POPUP
//CLUE POPUP
clueScore = (TextView) layout.findViewById(R.id.clueScore);
clue = (TextView) layout.findViewById(R.id.clue);
//GET SCORE getting preferences
SharedPreferences prefs = this.getSharedPreferences("Score", Context.MODE_PRIVATE);
int savedScore = prefs.getInt("key", 100); //0 is the default value**
gameScore.setText(Integer.toString(savedScore));
clueScore.setText(gameScore.getText().toString());
//GET SCORE
}
答案 0 :(得分:0)
由于您在LogCat
输出中有此消息:
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
和OutOfMemoryError
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3054)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
布局中引用的一些图像尺寸很大,需要显示大量内存。