致命的例外:主要. lang。运行时异常:无法启动大量的错误

时间:2023-01-17 10:32:43

I added scrollview in my activity_main.xml and its not working anymore. Before scrollview it did not work on Samsung s3,s4. But it worked on other phones and tablets.

我在activity_main中添加了scrollview。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);
    }
}

2 个解决方案

#1


1  

You've got this error in setContentView(R.layout.activity_main); and its because of memory problems. It seems you've used a big image. You must scale down your image.

在setContentView(R.layout.activity_main)中有这个错误;这是由于记忆问题。看来你用的是大图。你必须缩小你的形象。

#2


0  

Change

改变

setContentView(R.layout.activity_main);

to

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

#1


1  

You've got this error in setContentView(R.layout.activity_main); and its because of memory problems. It seems you've used a big image. You must scale down your image.

在setContentView(R.layout.activity_main)中有这个错误;这是由于记忆问题。看来你用的是大图。你必须缩小你的形象。

#2


0  

Change

改变

setContentView(R.layout.activity_main);

to

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