java.lang.RuntimeException:无法启动活动

时间:2014-04-08 20:21:19

标签: java android eclipse android-intent android-activity

强调文字

04-09 02:16:18.029: E/AndroidRuntime(6560): FATAL EXCEPTION: main<br>
04-09 02:16:18.029: E/AndroidRuntime(6560): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.game.lutung/com.game.lutung.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.os.Handler.dispatchMessage(Handler.java:99)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.os.Looper.loop(Looper.java:123)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.ActivityThread.main(ActivityThread.java:3683)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at java.lang.reflect.Method.invokeNative(Native Method)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at java.lang.reflect.Method.invoke(Method.java:507)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at dalvik.system.NativeStart.main(Native Method)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.Activity.setContentView(Activity.java:1657)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at com.game.lutung.MainActivity.onCreate(MainActivity.java:40)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     ... 11 more
<br>04-09 02:16:18.029: E/AndroidRuntime(6560): Caused by: java.lang.reflect.InvocationTargetException
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at java.lang.reflect.Constructor.constructNative(Native Method)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     ... 21 more
<br>04-09 02:16:18.029: E/AndroidRuntime(6560): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.View.<init>(View.java:1951)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.View.<init>(View.java:1899)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.view.ViewGroup.<init>(ViewGroup.java:286)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
<br>04-09 02:16:18.029: E/AndroidRuntime(6560):     ... 24 more

代码:

   package com.game.lutung;

   import java.sql.SQLException;

   import com.game.dbcontroller.DBCreateBahasa;
   import com.game.dbcontroller.DBCreateLevel;
   import com.game.model.Level;
   import com.game.view.Komik;

   import android.app.Activity;
   import android.content.Context;
   import android.content.Intent;
   import android.database.Cursor;
   import android.database.sqlite.SQLiteDatabase;
   import android.os.Bundle;
   import android.view.KeyEvent;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.view.Window;
   import android.view.WindowManager;
   import android.widget.Button;
   import android.widget.ImageView;

   public class PilihLevel extends Activity {
     final Context context = this;

     private DBCreateBahasa dbCreateBahasa;
     private DBCreateLevel dbCreateLevel;
     private LutungCreate lutungCreate;
     private LutungSetPosition lutungSetPosition;
private SQLiteDatabase database;

private String jenisBahasa;

private ImageView judul;
private ImageView level1;
private ImageView level2;
private ImageView level3;
private ImageView level4;
private ImageView level5;
private ImageView level6;

private int id_level;
private String level;
private String status;
private String keterangan;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.pilih_level);

    //suara
    Sound.setOST(context);

    //pamanggilan class DBCreateBahasa
    dbCreateBahasa = new DBCreateBahasa(context);
    dbCreateBahasa.open();
    jenisBahasa=dbCreateBahasa.getBahasaTerpilih();

    judul = (ImageView)findViewById(R.id.judulLevel);

    //method untuk setting bahasa
    setBahasa();

    //pemanggilan class DBCreateLevel
    dbCreateLevel = new DBCreateLevel(context);
    try {
        dbCreateLevel.open();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    database = openOrCreateDatabase("lutung.db", MODE_PRIVATE, null);

    //pemanggilan class
    lutungCreate = new LutungCreate();
    lutungSetPosition = new LutungSetPosition();

    level1 = (ImageView)findViewById(R.id.level1);
    level2 = (ImageView)findViewById(R.id.level2);
    level3 = (ImageView)findViewById(R.id.level3);
    level4 = (ImageView)findViewById(R.id.l4);
    level5 = (ImageView)findViewById(R.id.level5);
    level6 = (ImageView)findViewById(R.id.level6);

    //method cek level
    cekLevelInDatabase();

    //tombol untuk level 1
    level1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Sound.setButtonClick(context);
            dbCreateLevel.pilihLevel(1, "digunakan");
            Intent cerita = new Intent(context, Komik.class);
            startActivity(cerita);
        }
    });
}

//method setting bahasa
private void setBahasa() {
    if(jenisBahasa.equals("English")){
        judul.setImageResource(R.drawable.level);
    }/*else if(jenisBahasa.equals("Sunda")){
        judul.setImageResource(R.drawable.level);
    }*/
}

//method cek level
private void cekLevelInDatabase() {
    //query
    Cursor cursor = database.rawQuery("SELECT * FROM level WHERE keterangan = 'terbuka'", null);
    cursor.moveToFirst();
    if(cursor.getCount() > 0){
        while(true){
            id_level = cursor.getInt(cursor.getColumnIndex("id_level"));
            level = cursor.getString(cursor.getColumnIndex("level"));
            status = cursor.getString(cursor.getColumnIndex("status"));
            keterangan = cursor.getString(cursor.getColumnIndex("keterangan"));

            System.out.println("id_level:"+id_level+", level :"+level+", status:"+status+", keterangan:"+keterangan);

            //tombol untuk level 2
            if(id_level == 2){
                level2.setImageResource(R.drawable.level2);
                level2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Sound.setButtonClick(context);
                        dbCreateLevel.pilihLevel(2, "digunakan");
                        Intent cerita = new Intent(context, Komik.class);
                        startActivity(cerita);
                    }
                });
            //tombol untuk level 3
            }else if(id_level == 3){
                level3.setImageResource(R.drawable.level3);
                level3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Sound.setButtonClick(context);
                        dbCreateLevel.pilihLevel(3, "digunakan");
                        Intent cerita = new Intent(context, Komik.class);
                        startActivity(cerita);
                    }
                });
            //tombol untuk level 4
            }else if (id_level == 4){
                level4.setImageResource(R.drawable.level4);
                level4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Sound.setButtonClick(context);
                        dbCreateLevel.pilihLevel(4, "digunakan");
                        Intent cerita = new Intent(context, Komik.class);
                        startActivity(cerita);
                    }
                });
            //tombol untuk level 5
            }else if(id_level == 5){
                level5.setImageResource(R.drawable.level5);
                level5.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Sound.setButtonClick(context);
                        dbCreateLevel.pilihLevel(5, "digunakan");
                        Intent cerita = new Intent(context,
                                Komik.class);
                        startActivity(cerita);
                    }
                });
            //tombol untuk level 6
            }else if(id_level == 6){
                level6.setImageResource(R.drawable.level6);
                level6.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Sound.setButtonClick(context);
                        dbCreateLevel.pilihLevel(6, "digunakan");
                        Intent cerita = new Intent(context,
                                Komik.class);
                        startActivity(cerita);
                    }
                });
            }

            if(!cursor.moveToNext())
                break;
        }
    }else{
        System.out.println("data tidak ada");
    }
    cursor.close();
}

//method untuk kembali ke halaman utama
public boolean onKeyDown(int keyCode, KeyEvent event){
    if(keyCode == KeyEvent.KEYCODE_BACK){
        Sound.setOSTMainStop(context);
        Intent home = new Intent(this, MainActivity.class);
        startActivity(home);
        //dbCreateLevel.close();
        //dbCreateBahasa.close();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

}

1 个答案:

答案 0 :(得分:0)

当您查看Exception的堆栈跟踪时,您将看到根本原因:

OutOfMemoryError: bitmap size exceeds VM budget

这意味着您正在尝试加载对于可用内存而言太大的图像。没有其他解决方案可以使用较小的图像。

修改

Here是有关处理大图像的更多信息。