Android App在onCreate()中崩溃;主要活动

时间:2016-05-01 00:32:14

标签: java android xml

我试图开始另一项活动,但当我在主要活动和velocidad的活动之间进行几次更改时,主要活动在onCreate中崩溃。

我找到的唯一解决方案是" finish();"当我从主要去Velocidad,但我需要保持主要在线。

错误:

05-01 19:21:07.631 19529-19529/nitro.control E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: nitro.control, PID: 19529
                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{nitro.control/nitro.control.Main}: android.view.InflateException: Binary XML file line #10: Binary XML file line #2: Error inflating class <unknown>
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                   at android.os.Looper.loop(Looper.java:158)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #2: Error inflating class <unknown>
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
                                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                   at nitro.control.Main.onCreate(Main.java:54)
                                                                   at android.app.Activity.performCreate(Activity.java:6876)
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                   at android.os.Looper.loop(Looper.java:158) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                                                                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:966)
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                   at nitro.control.Main.onCreate(Main.java:54) 
                                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                   at android.os.Looper.loop(Looper.java:158) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                   at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631)
                                                                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706) 
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774) 
                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:966) 
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:843) 
                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                   at nitro.control.Main.onCreate(Main.java:54) 
                                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                   at android.os.Looper.loop(Looper.java:158) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                Caused by: java.lang.OutOfMemoryError: Failed to allocate a 35443212 byte allocation with 16766160 free bytes and 19MB until OOM
                                                                   at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856)
                                                                   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675)
                                                                   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228)
                                                                   at android.content.res.Resources.loadDrawableForCookie(Resources.java:4211)
                                                                   at android.content.res.Resources.loadDrawable(Resources.java:4085)
                                                                   at android.content.res.Resources.loadDrawable(Resources.java:3935)
                                                                   at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
                                                                   at android.view.View.<init>(View.java:4225)
                                                                   at android.view.ViewGroup.<init>(ViewGroup.java:589)
                                                                   at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
                                                                   at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
                                                                   at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
                                                                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
                                                                   at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                                   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706) 
                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774) 
                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:966) 
                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:843) 
                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                                   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                   at nitro.control.Main.onCreate(Main.java:54) 
                                                                   at android.app.Activity.performCreate(Activity.java:6876) 
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                   at android.os.Looper.loop(Looper.java:158) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

错误行:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Main.java:

package nitro.control;

import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;

public class Main extends AppCompatActivity {

    Button bt, history, cfg, vel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bt = (Button) findViewById(R.id.bt);
        history = (Button) findViewById(R.id.hist);
        cfg = (Button) findViewById(R.id.cfg);
        vel = (Button) findViewById(R.id.vel);

        vel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent vel = new Intent(getApplicationContext(), Velocidad.class);
                startActivity(vel);
                overridePendingTransition(R.anim.left_in, R.anim.left_out);
                finish(); // I want to don't use this line
            }
        });

    }

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

Velocidad.java:

package nitro.control;


import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import java.util.Random;

public class Velocidad extends Activity {

    Button main;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_velocidad);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        main = (Button) findViewById(R.id.main);

        main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent main = new Intent(getApplicationContext(), Main.class);
                startActivity(main);
                overridePendingTransition(R.anim.right_in, R.anim.right_out);
                finish();
            }
        });

    }

}

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true"
    tools:context="nitro.control.Main">

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

content_main.xml:

<?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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="nitro.control.Main"
    tools:showIn="@layout/activity_main"
    android:background="@drawable/fondo">

    <ImageView
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:id="@+id/logo"
        android:src="@drawable/logo"
        android:layout_alignParentTop="true"
        android:layout_marginRight="15dp"
        android:layout_alignParentRight="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bt"
        android:layout_above="@+id/hist"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="70dp"
        android:background="@drawable/state_connect"
        android:enabled="true"
        android:clickable="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/hist"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/state_history"
        android:enabled="true"
        android:clickable="true" />

    <Button
        android:layout_width="130dp"
        android:layout_height="53dp"
        android:id="@+id/cfg"
        android:layout_below="@+id/hist"
        android:layout_marginTop="75dp"
        android:background="@drawable/state_cfg"
        android:layout_alignLeft="@+id/hist"
        android:layout_alignStart="@+id/hist"
        android:layout_alignRight="@+id/hist"
        android:layout_alignEnd="@+id/hist"
        android:clickable="true"
        android:enabled="true" />

    <Button
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:id="@+id/vel"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:background="@drawable/der"
        android:enabled="true"
        android:clickable="true" />

</RelativeLayout>

activity_velocidad.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true"
    tools:context="nitro.control.Main">

    <include layout="@layout/content_velocidad" />

</android.support.design.widget.CoordinatorLayout>

content_velocidad.xml:

<?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"
    xmlns:gauge="pl.pawelkleczkowski.customgauge.CustomGauge"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="nitro.control.Velocidad"
    tools:showIn="@layout/activity_velocidad"
    android:background="@drawable/fondo">

    <ImageView
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:id="@+id/logo"
        android:src="@drawable/logo"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="false"
        android:layout_alignParentTop="true"
        android:layout_marginRight="15dp" />

    <Button
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:id="@+id/main"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="false"
        android:clickable="true"
        android:enabled="true"
        android:background="@drawable/izq" />

</RelativeLayout>

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nitro.control">

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Main"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Velocidad"
            android:label="Control - Nitro"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
    </application>

</manifest>

0 个答案:

没有答案