应用程序模拟器崩溃

时间:2013-10-31 13:17:11

标签: android emulation avd

每次我尝试运行模拟器时都会崩溃。这是我收到的logCat:

10-31 09:09:59.104: W/dalvikvm(1840): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-31 09:09:59.453: E/AndroidRuntime(1840): FATAL EXCEPTION: main
10-31 09:09:59.453: E/AndroidRuntime(1840): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.secondapp/com.example.secondapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.os.Looper.loop(Looper.java:137)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at java.lang.reflect.Method.invokeNative(Native Method)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at java.lang.reflect.Method.invoke(Method.java:525)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at dalvik.system.NativeStart.main(Native Method)
10-31 09:09:59.453: E/AndroidRuntime(1840): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.Activity.setContentView(Activity.java:1895)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.example.secondapp.MainActivity.onCreate(MainActivity.java:19)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.Activity.performCreate(Activity.java:5133)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-31 09:09:59.453: E/AndroidRuntime(1840):     ... 11 more
10-31 09:09:59.453: E/AndroidRuntime(1840): Caused by: java.lang.reflect.InvocationTargetException
10-31 09:09:59.453: E/AndroidRuntime(1840):     at     java.lang.reflect.Constructor.constructNative(Native Method)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at     java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
10-31 09:09:59.453: E/AndroidRuntime(1840):     ... 23 more
10-31 09:09:59.453: E/AndroidRuntime(1840): Caused by: java.lang.OutOfMemoryError
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.content.res.Resources.loadDrawable(Resources.java:2105)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.View.<init>(View.java:3364)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.view.ViewGroup.<init>(ViewGroup.java:457)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.widget.LinearLayout.<init>(LinearLayout.java:176)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.widget.LinearLayout.<init>(LinearLayout.java:172)
10-31 09:09:59.453: E/AndroidRuntime(1840):     ... 26 more
10-31 09:09:59.643: D/dalvikvm(1840): GC_FOR_ALLOC freed 62704K, 96% free 2693K/65536K, paused 164ms, total 166ms
10-31 09:10:22.983: I/Process(1840): Sending signal. PID: 1840 SIG: 9

这是我的Java代码:

package com.example.secondapp;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {

MediaPlayer ourSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.happyman);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(1000);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent startMain = new Intent("com.example.secondapp.MainActivity");
                startActivity(startMain);
            }
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}

}

我已经尝试了所有修复它的东西,但我似乎无法找到问题。有人可以帮我吗?

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@drawable/background1"

&GT;      

1 个答案:

答案 0 :(得分:0)

你已经在评论中找到了解决方案,但是这里是你如何调试这样的堆栈跟踪:

10-31 09:09:59.453: E/AndroidRuntime(1840): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.secondapp/com.example.secondapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>

XML布局文件行#1中的问题。

再向下:

10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.app.Activity.setContentView(Activity.java:1895)
10-31 09:09:59.453: E/AndroidRuntime(1840):     at com.example.secondapp.MainActivity.onCreate(MainActivity.java:19)

查看代码:

     setContentView(R.layout.splash);

所以它是layout/splash.xml文件。

此外:

10-31 09:09:59.453: E/AndroidRuntime(1840): Caused by: java.lang.OutOfMemoryError
10-31 09:09:59.453: E/AndroidRuntime(1840):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

解码资产(可绘制资源)位图时,内存不足。

splash.xml第一行元素中,只有一个对可绘制资源的引用:

android:background="@drawable/background1"

所以解决方法是检查background1 drawable并将其缩小,以便解码它不会占用太多内存。