2013-05-16 75 views
-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,請幫我

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> 
+1

這意味着您的代碼存在問題 – chopchop

+0

xml有問題。 Post Splash和它膨脹的xml – Blackbelt

+1

java.lang.OutOfMemoryError看起來很有趣。也許你試圖膨脹的飛濺圖像的Drawable太大了? –

回答

0

的名字說明了一切OutOfMemoryError意味着你試圖分配多於你應該。

com.thenewboston.travis.Splash意味着你正在爲你的飛濺活動做到這一點。

結論是你試圖設置一個非常大的圖像作爲背景。我建議使用1或2 9-patches來最小化尺寸。

0
  1. 產生的原因:android.view.InflateException:二進制XML文件中的行#2

它不過是在XML文件中有些不妥。

  1. 造成的:java.lang.reflect.InvocationTargetException

在其力所能及的一些變量有你試圖讓空值。

  1. 產生的原因:java.lang.OutOfMemoryError

它,當你用它來獲得太大的圖像或大尺寸圖片時。大多數情況下,只要您使用相機意圖拍攝照片,就會發生在Galaxy S3手機中。

+0

感謝您的支持。由於使用了錯誤的大小模擬器,我得到了這個異常。在我升級仿真器配置後,異常沒有發生 – user2235614

相關問題