应用程序在启动意图时崩溃

时间:2018-02-19 07:54:44

标签: android

据说,当我点击它时,它应该只有一个背景的新意图,但它只是崩溃。

logcat的:

15392-15392/com.carschoolingpromo.scires.carschooling E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.carschoolingpromo.scires.carschooling, PID: 15392
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.carschoolingpromo.scires.carschooling/com.carschoolingpromo.scires.carschooling.CE2}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
   at android.app.ActivityThread.-wrap14(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6692)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Constructor.newInstance0(Native Method)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
   at android.view.LayoutInflater.createView(LayoutInflater.java:652)
   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:724)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:792)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
   at com.carschoolingpromo.scires.carschooling.CE2.onCreate(CE2.java:11)
   at android.app.Activity.performCreate(Activity.java:6912)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
   at android.app.ActivityThread.-wrap14(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6692)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 15500812 byte allocation with 8861456 free bytes and 8MB until OOM
   at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:700)
   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:535)
   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1179)
   at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:770)
   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)
   at android.content.res.Resources.loadDrawable(Resources.java:1727)
   at android.content.res.TypedArray.getDrawable(TypedArray.java:945)
   at android.view.View.<init>(View.java:4524)
   at android.view.ViewGroup.<init>(ViewGroup.java:579)
   at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
02-19 15:47:46.202 15392-15392/com.carschoolingpromo.scires.carschooling E/AndroidRuntime:     at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
   at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
    ... 25 more

CLASS:

package com.carschoolingpromo.scires.carschooling;


import org.w3c.dom.Text;

public class Calculator extends AppCompatActivity {

    double counter =0;

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

        Button caremissionscheck = findViewById(R.id.checkcar);
        caremissionscheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent tocarbonemissions = new Intent(Calculator.this, CE2.class);
                startActivity(tocarbonemissions);
            }
        });

        final Button distancecheck = findViewById(R.id.checkdestination);
        distancecheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent checkdistance = new Intent(Calculator.this, DistancesList.class);
                startActivity(checkdistance);
            }
        });

        final Button multiply =(Button)findViewById(R.id.multiplycounter);
        final EditText num1 =(EditText)findViewById(R.id.carboninput);
        final EditText num2 =(EditText)findViewById(R.id.distanceinput);
        final TextView ans =(TextView)findViewById(R.id.answer);
        final Button gotonext=(Button)findViewById(R.id.nextsequence);

        multiply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double n1 = Double.parseDouble(num1.getText().toString());
                double n2 = Double.parseDouble(num2.getText().toString());

                //ans.setText(String.valueOf(n1*n2));
                ans.setText( String.format( "%.2f", n1*n2) );

                Button gettotal;
                gettotal=(Button)findViewById(R.id.carpooltoday);
                gettotal.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        double n1 = Double.parseDouble(num1.getText().toString());
                       double n2 = Double.parseDouble(num2.getText().toString());
                        counter =counter+(n1*n2);
                        final TextView totalemission;

                        totalemission=(TextView)findViewById(R.id.total);
                        totalemission.setText(String.valueOf(counter));
                        totalemission.setText( String.format( "%.2f", counter) );


                        if(counter>7000){
                           ImageButton level1=(ImageButton)findViewById(R.id.badge);
                           level1.setEnabled(true);
                           level1.setVisibility(View.VISIBLE);
                           level1.setOnClickListener(new View.OnClickListener() {
                               @Override
                               public void onClick(View view) {
                                   Intent reward1 =new Intent(Calculator.this, Reward1.class);
                                   startActivity(reward1);
                               }
                           });
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(false);
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(false);
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(false);
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(false);
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(false);



                        }
                        if(counter>8000){
                            ImageButton level1=(ImageButton)findViewById(R.id.badge);
                            level1.setEnabled(false);
                            level1.setVisibility(View.INVISIBLE);
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(true);
                            level2.setVisibility(View.VISIBLE);
                            level2.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent level2 = new Intent(Calculator.this, Reward2.class);
                                    startActivity(level2);
                                }
                            });
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(false);
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(false);
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(false);
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(false);


                        }
                        if(counter>9000){

                            ImageButton level1=(ImageButton)findViewById(R.id.badge);
                            level1.setEnabled(false);
                            level1.setVisibility(View.INVISIBLE);
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(false);
                            level2.setVisibility(View.INVISIBLE);
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(true);
                            level3.setVisibility(View.VISIBLE);
                            level3.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent level3 = new Intent(Calculator.this, Reward3.class);
                                    startActivity(level3);
                                }
                            });
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(false);
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(false);
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(false);

                        }
                        if(counter>10000){

                            ImageButton level1=(ImageButton)findViewById(R.id.badge);
                            level1.setEnabled(false);
                            level1.setVisibility(View.INVISIBLE);
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(false);
                            level2.setVisibility(View.INVISIBLE);
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(false);
                            level3.setVisibility(View.INVISIBLE);
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(true);
                            level4.setVisibility(View.VISIBLE);
                            level4.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent level4 = new Intent(Calculator.this, Reward4.class);
                                    startActivity(level4);
                                }
                            });
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(false);
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(false);



                        }



                        if(counter>11000){

                            ImageButton level1=(ImageButton)findViewById(R.id.badge);
                            level1.setEnabled(false);
                            level1.setVisibility(View.INVISIBLE);
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(false);
                            level2.setVisibility(View.INVISIBLE);
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(false);
                            level3.setVisibility(View.INVISIBLE);
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(false);
                            level4.setVisibility(View.INVISIBLE);
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(true);
                            level5.setVisibility(View.VISIBLE);
                            level5.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent level5 = new Intent(Calculator.this, Reward5.class);
                                    startActivity(level5);
                                }
                            });
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(false);


                        }

                        if(counter>12000){
                            ImageButton level1=(ImageButton)findViewById(R.id.badge);
                            level1.setEnabled(false);
                            level1.setVisibility(View.INVISIBLE);
                            ImageButton level2=(ImageButton)findViewById(R.id.badge2);
                            level2.setEnabled(false);
                            level2.setVisibility(View.INVISIBLE);
                            ImageButton level3=(ImageButton)findViewById(R.id.badge3);
                            level3.setEnabled(false);
                            level3.setVisibility(View.INVISIBLE);
                            ImageButton level4=(ImageButton)findViewById(R.id.badge4);
                            level4.setEnabled(false);
                            level4.setVisibility(View.INVISIBLE);
                            ImageButton level5=(ImageButton)findViewById(R.id.badge5);
                            level5.setEnabled(false);
                            level5.setVisibility(View.INVISIBLE);
                            ImageButton level6=(ImageButton)findViewById(R.id.badge6);
                            level6.setEnabled(true);
                            level6.setVisibility(View.VISIBLE);
                            gotonext.setVisibility(View.VISIBLE);

                            gotonext.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent k = new Intent(Calculator.this, Survey.class);
                                    startActivity(k);
                                }
                            });
                            level6.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent level6 = new Intent(Calculator.this, Reward6.class);
                                    startActivity(level6);


                                }
                            });


                        }








            }
        });


            }



    });}}

XML OF ce2.class:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.carschoolingpromo.scires.carschooling.CE2"
    android:background="@drawable/ce">

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

来自Logcat消息:

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 15500812 byte allocation with 8861456 free bytes and 8MB until OOM

明确你的@drawable/ce记忆力很强。尝试制作不同的版本(mdpi,hdpi,...)。您可以尝试将该drawable放在nodpi目录中。 nodpi目录图像不会缩放。

如果您仍然遇到此问题,请使用android:largeHeap="true"文件中application标记内的AndroidManifest.xml