-2

在启动我的应用程序时,我收到以下异常:

我在下面添加我的代码请检查一次

05-16 10:44:16.653: E/AndroidRuntime(979): FATAL EXCEPTION: main
05-16 10:44:16.653: E/AndroidRuntime(979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thenewboston.travis/com.thenewboston.travis.Splash}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.os.Looper.loop(Looper.java:137)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread.main(ActivityThread.java:5039)
05-16 10:44:16.653: E/AndroidRuntime(979):  at java.lang.reflect.Method.invokeNative(Native Method)
05-16 10:44:16.653: E/AndroidRuntime(979):  at java.lang.reflect.Method.invoke(Method.java:511)
05-16 10:44:16.653: E/AndroidRuntime(979):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-16 10:44:16.653: E/AndroidRuntime(979):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-16 10:44:16.653: E/AndroidRuntime(979):  at dalvik.system.NativeStart.main(Native Method)
05-16 10:44:16.653: E/AndroidRuntime(979): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-16 10:44:16.653: E/AndroidRuntime(979):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-16 10:44:16.653: E/AndroidRuntime(979):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.Activity.setContentView(Activity.java:1881)
05-16 10:44:16.653: E/AndroidRuntime(979):  at com.thenewboston.travis.Splash.onCreate(Splash.java:16)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.Activity.performCreate(Activity.java:5104)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-16 10:44:16.653: E/AndroidRuntime(979):  ... 11 more
05-16 10:44:16.653: E/AndroidRuntime(979): Caused by: java.lang.reflect.InvocationTargetException
05-16 10:44:16.653: E/AndroidRuntime(979):  at java.lang.reflect.Constructor.constructNative(Native Method)
05-16 10:44:16.653: E/AndroidRuntime(979):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-16 10:44:16.653: E/AndroidRuntime(979):  ... 23 more
05-16 10:44:16.653: E/AndroidRuntime(979): Caused by: java.lang.OutOfMemoryError
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.content.res.Resources.loadDrawable(Resources.java:1965)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.View.<init>(View.java:3328)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.view.ViewGroup.<init>(ViewGroup.java:431)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-16 10:44:16.653: E/AndroidRuntime(979):  at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-16 10:44:16.653: E/AndroidRuntime(979):  ... 26 more

我在下面添加我的代码,一旦我不知道为什么会发生膨胀异常,请检查我是 Android 新手,请帮助我

飞溅.java

package com.thenewboston.travis;

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

public class Splash extends Activity{
MediaPlayer mySong;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        mySong = MediaPlayer.create(Splash.this, R.raw.honey);

        SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        boolean musicChk = getPrefs.getBoolean("checkbox", true);
        if(musicChk == true)

            mySong.start();

        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(1000);
                }
                catch(InterruptedException e){
                    e.printStackTrace();                    
                }finally{
                    System.out.println("Coming HERE...............");
                    Intent openStartingPoint = new Intent ("com.thenewboston.travis.MENU");
                    startActivity(openStartingPoint); 

                }
            }
        };
        timer.start();
    }

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


}

飞溅.xml

<?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/honey">


</LinearLayout>
4

2 回答 2

0
  1. 引起:android.view.InflateException:二进制 XML 文件第 2 行

它只不过是您的 xml 文件中的问题。

  1. 引起:java.lang.reflect.InvocationTargetException

这意味着某些变量具有您尝试获取的空值。

  1. 引起:java.lang.OutOfMemoryError

当您使用太大的图像或大尺寸的图像时会发生这种情况。每当您使用相机意图拍照时,它通常会出现在 Galaxy s3 手机中。

于 2013-05-16T11:01:06.790 回答
0

顾名思义,这一切都OutOfMemoryError意味着你试图分配比你应该分配的更多。

com.thenewboston.travis.Splash意味着你在你的splash activty中这样做。

结论是您正在尝试将一个非常大的图像设置为背景。我建议通过使用 1 或 2 来最小化大小9-patches

于 2013-05-16T10:55:25.577 回答