致命异常:主要了java.lang.RuntimeException:无法启动活动了很多的bug(F

2019-10-21 22:05发布

我添加scrollview在我activity_main.xml和不再工作。 之前scrollview并没有对三星S3,S4工作。 但它的工作对其他手机和平板电脑。

02-15 05:37:35.700: D/AndroidRuntime(936): Shutting down VM
02-15 05:37:35.700: W/dalvikvm(936): threadid=1: thread exiting with uncaught exception (group=0xb2a78ba8)
02-15 05:37:35.780: E/AndroidRuntime(936): FATAL EXCEPTION: main
02-15 05:37:35.780: E/AndroidRuntime(936): Process: com.oxygen.hayvansesleri, PID: 936
02-15 05:37:35.780: E/AndroidRuntime(936): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oxygen.hayvansesleri/com.oxygen.hayvansesleri.screencat}: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.os.Handler.dispatchMessage(Handler.java:102)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.os.Looper.loop(Looper.java:136)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread.main(ActivityThread.java:5017)
02-15 05:37:35.780: E/AndroidRuntime(936):  at java.lang.reflect.Method.invokeNative(Native Method)
02-15 05:37:35.780: E/AndroidRuntime(936):  at java.lang.reflect.Method.invoke(Method.java:515)
02-15 05:37:35.780: E/AndroidRuntime(936):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-15 05:37:35.780: E/AndroidRuntime(936):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-15 05:37:35.780: E/AndroidRuntime(936):  at dalvik.system.NativeStart.main(Native Method)
02-15 05:37:35.780: E/AndroidRuntime(936): Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
02-15 05:37:35.780: E/AndroidRuntime(936):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-15 05:37:35.780: E/AndroidRuntime(936):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.Activity.setContentView(Activity.java:1929)
02-15 05:37:35.780: E/AndroidRuntime(936):  at com.oxygen.hayvansesleri.screencat.onCreate(screencat.java:18)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.Activity.performCreate(Activity.java:5231)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-15 05:37:35.780: E/AndroidRuntime(936):  ... 11 more
02-15 05:37:35.780: E/AndroidRuntime(936): Caused by: java.lang.reflect.InvocationTargetException
02-15 05:37:35.780: E/AndroidRuntime(936):  at java.lang.reflect.Constructor.constructNative(Native Method)
02-15 05:37:35.780: E/AndroidRuntime(936):  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
02-15 05:37:35.780: E/AndroidRuntime(936):  ... 24 more
02-15 05:37:35.780: E/AndroidRuntime(936): Caused by: java.lang.OutOfMemoryError
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.content.res.Resources.loadDrawable(Resources.java:2110)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.widget.ImageView.<init>(ImageView.java:129)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.widget.ImageButton.<init>(ImageButton.java:87)
02-15 05:37:35.780: E/AndroidRuntime(936):  at android.widget.ImageButton.<init>(ImageButton.java:83)
02-15 05:37:35.780: E/AndroidRuntime(936):  ... 27 more
02-15 05:37:42.930: W/Ads(936): There was a problem getting an ad response. ErrorCode: 0
02-15 05:37:47.120: I/Process(936): Sending signal. PID: 936 SIG: 9

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView adView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

        final MediaPlayer click = MediaPlayer.create(MainActivity.this,
                R.raw.click);

        ImageButton catbutton = (ImageButton) findViewById(R.id.catbutton);
        catbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screencat.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton dogbutton = (ImageButton) findViewById(R.id.dogbutton);
        dogbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screendog.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton bearbutton = (ImageButton) findViewById(R.id.bearbutton);
        bearbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screenbear.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton cowbutton = (ImageButton) findViewById(R.id.cowbutton);
        cowbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screencow.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton duckbutton = (ImageButton) findViewById(R.id.duckbutton);
        duckbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screenduck.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
        ImageButton hindibutton = (ImageButton) findViewById(R.id.hindibutton);
        hindibutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screenhindi.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
        ImageButton lionbutton = (ImageButton) findViewById(R.id.lionbutton);
        lionbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screenlion.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
        ImageButton tigerbutton = (ImageButton) findViewById(R.id.tigerbutton);
        tigerbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screentiger.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
        ImageButton donkeybutton = (ImageButton) findViewById(R.id.donkeybutton);
        donkeybutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this,
                        screendonkey.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton horsebutton = (ImageButton) findViewById(R.id.horsebutton);
        horsebutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screenhorse.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        ImageButton goatbutton = (ImageButton) findViewById(R.id.goatbutton);
        goatbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                click.start();

                Intent intent = new Intent(MainActivity.this, screengoat.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Answer 1:

你必须在这个错误setContentView(R.layout.activity_main); 和它的,因为内存问题。 看来你已经使用了一个大的图像。 你必须缩小图像。



Answer 2:

更改

setContentView(R.layout.activity_main);

View _mw = getLayoutInflater().inflate(R.layout.activity_main, null);
setContentView(_mw);


Answer 3:

E / AndroidRuntime:致命异常:主要过程:com.kushagra.dynamiclist,PID:2456 android.view.InflateException:二进制XML文件行#9:错误充气类未知

得到了相同的问题,浪费我的时间试图找到问题所在。 我的应用程序在这两个模拟器和真实设备工作的很好的手机,但在使用平板电脑或更大屏幕的那些坠毁。 我也尝试增加我的内存堆,但没有帮助。 我一直在使用ListView控件使用Android:背景=“@绘制/ edittextborder”,这是崩溃的源头。 不知道为什么或如何,但去除解决这个问题对我来说。

 <LinearLayout android:background="@drawable/edittextborder" android:layout_margin="5dp" android:id="@+id/allListData" android:padding="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/logo" android:layout_width="30dp" android:layout_height="30dp" /> <TextView android:paddingLeft="10dp" android:id="@+id/listName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello"/> </LinearLayout> 



文章来源: Fatal Exception: main java.lang.RuntimeException: Unable to start activity a lot of bug