同時發動我的應用我得到以下異常:我可以知道爲什麼會發生此異常嗎?
我在低於加入我的代碼,請檢查一次
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,請幫我
Splash.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();
}
}
Splash.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>
這意味着您的代碼存在問題 – chopchop
xml有問題。 Post Splash和它膨脹的xml – Blackbelt
java.lang.OutOfMemoryError看起來很有趣。也許你試圖膨脹的飛濺圖像的Drawable太大了? –