0

I'm trying to start another activity, but when i change between main's activity and velocidad's activity a few times, the main's activity crash in onCreate.

The only solution i was found is putting "finish();" when i go from main to velocidad, but i need to keep main online.

Error:

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) 

Error Line:

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>
Inroo
  • 1
  • 3
  • It's great that you provided all the code, but without more of the error, we can't know what the actual problem is other than some XML is wrong – OneCricketeer May 01 '16 at 17:05
  • I'm in that, give me a second, and sorry! – Inroo May 01 '16 at 22:16
  • I think `tools:context="nitro.control.Main"` is not correct in the Velocidad layout – OneCricketeer May 01 '16 at 22:18
  • Or you don't need to redefine the `xmlns` attributes in your content layouts – OneCricketeer May 01 '16 at 22:20
  • I've tried changing `tools:context="nitro.control.Main"` to `tools:context="nitro.control.Main"` and deleting `xmlns` attributes but still crashes – Inroo May 01 '16 at 22:26
  • You changed it to the same thing? Anyways, you don't need to use content layouts. I would try to move your layouts just into the activity xml files. The only reason to include another layout is if you are going to use it elsewhere – OneCricketeer May 01 '16 at 22:28
  • The actual problem is that your images are too large.. – OneCricketeer May 01 '16 at 22:31
  • I've deteled the content layouts and used the activity layouts directly, but still same.. – Inroo May 01 '16 at 22:32
  • Read the very last "Caused by" in the error. That is how you read a stacktrace. You'd be surprised how easily searchable some Android errors actually are – OneCricketeer May 01 '16 at 22:34
  • Now i see it, but i can't find the answer to 'clean' the Memory, 'cause i'm not using bitmaps, i'm using img background to buttons.. – Inroo May 01 '16 at 22:49
  • The ImageView isn't using a background. It's using a src drawable logo. – OneCricketeer May 01 '16 at 23:55
  • Yes i know, but i can't find how can 'recycle' or 'delete' the memory when i left the activity. – Inroo May 02 '16 at 01:58
  • You should use a proper image loading library. There are multiple that exist. I use Picasso – OneCricketeer May 02 '16 at 02:10
  • But i'm putting the drawable background in `activity_main.xml`. You mean that i need to put the background in `Main.java`? – Inroo May 02 '16 at 02:44
  • You seem to be loading a raw image resource that is too large for the system memory, so yes. – OneCricketeer May 02 '16 at 02:49

0 Answers0