(Solved) Error running Android app on mobile but working on other devices and emulator

Asked

Viewed 261 times

0

[Solution]: The solution found was to add the attributes android:hardwareAccelerated="false" , android:largeHeap="true" in the manifest


I’ve been dealing with Android for a while and I got this error recently during an evaluative activity at school, where we had to make a basic app of two activities, the second receiving data from the first. On my phone it hangs and closes when passing to second, nor displaying it, but the teacher’s device (both bike g) worked perfectly; in the native emulator of Android, already in my home, also rode perfectly. I would like help to solve this, I have done numerous apps with this and is the first that occurs the problem From now on, thank you!

Details: already tested with button events inside and outside the onCreate (setOnClickListener and defining function normally and using attribute android:onClick); I tried to decrease the image as suggested

The version of the phone that ran I’m not sure; in the emulator is an API 25, I believe 7.1 or 7.2 and on my phone is 7.0, API 24

Errors of the logcat:

04-16 16:39:18.436 25496-25496/sqlite.studio.com.identifique E/AndroidRuntime: FATAL EXCEPTION: main
    Process: sqlite.studio.com.identifique, PID: 25496
    java.lang.RuntimeException: Unable to start activity ComponentInfo{sqlite.studio.com.identifique/sqlite.studio.com.identifique.Main2Activity}: android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6123)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
     Caused by: android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class <unknown>
     Caused by: android.view.InflateException: Binary XML file line #47: 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:645)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:414)
        at android.app.Activity.setContentView(Activity.java:2418)
        at sqlite.studio.com.identifique.Main2Activity.onCreate(Main2Activity.java:21)
        at android.app.Activity.performCreate(Activity.java:6672)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6123)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
     Caused by: java.lang.OutOfMemoryError: Failed to allocate a 35190516 byte allocation with 16777216 free bytes and 16MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:724)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:575)
        at android.content.res.Resources.loadDrawable(Resources.java:854)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
        at android.widget.ImageView.<init>(ImageView.java:167)
04-16 16:39:18.436 25496-25496/sqlite.studio.com.identifique E/AndroidRuntime:     at android.widget.ImageView.<init>(ImageView.java:155)
        at android.widget.ImageView.<init>(ImageView.java:151)
            ... 27 more

XML main:

<?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="sqlite.studio.com.identifique.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:text="Bem vindo(a) ao desafio" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="IDENTIFIQUE AS BANDEIRAS"
        android:textSize="@dimen/grande" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="246dp"
        android:layout_height="234dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="99dp"
        android:background="@drawable/inicial" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="@dimen/margemLateral"
        android:layout_marginBottom="146dp"
        android:text="Como gostaria de ser chamado?" />

    <EditText
        android:id="@+id/nome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="89dp"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="" />

    <Button
        android:id="@+id/comecar"
        android:onClick="clique"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="29dp"
        android:text="começar" />

</RelativeLayout>

Mainactivity

package sqlite.studio.com.identifique;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    private EditText nomeUsuario;
    private Button comecar;

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

        nomeUsuario = (EditText) findViewById(R.id.nome);
        comecar = (Button) findViewById(R.id.comecar);

    }

    public void clique(View view){
        if(verificarNome()){
            mudarActivity();

        }else{
            AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
            alert.setTitle("ATENÇÃO");
            alert.setMessage("Preencha o campo nome");
            alert.setNeutralButton("OK", null);
            alert.show();
        }
    }

    public void mudarActivity(){
        String usuario = nomeUsuario.getText().toString();
        Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
        intent.putExtra("nomeUsuario", usuario);

        startActivity(intent);
    }

    public boolean verificarNome(){
        String nome = nomeUsuario.getText().toString();

        if(nome.isEmpty())
            return false;
        else
            return true;
    }
}

XML secondary:

<?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="sqlite.studio.com.identifique.Main2Activity">

    <TextView
        android:id="@+id/textoSaida"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:textSize="@dimen/medio"
        android:text=", identifique o nome do estado brasileiro de cada bandeira representada" />

    <ImageView
        android:id="@+id/imageTO"
        android:layout_width="@dimen/largura"
        android:layout_height="@dimen/altura"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="@dimen/margemLateral"
        android:layout_marginTop="63dp"
        android:src="@drawable/to" />

    <ImageView
        android:id="@+id/imageSP"
        android:layout_width="@dimen/largura"
        android:layout_height="@dimen/altura"
        android:layout_alignParentTop="true"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:layout_marginTop="153dp"
        android:src="@drawable/sp" />

    <ImageView
        android:id="@+id/imagePA"
        android:layout_width="@dimen/largura"
        android:layout_height="@dimen/altura"
        android:layout_alignParentBottom="true"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:layout_marginBottom="186dp"
        android:src="@drawable/pa" />

    <ImageView
        android:id="@+id/imageES"
        android:layout_width="@dimen/largura"
        android:layout_height="@dimen/altura"
        android:layout_alignParentBottom="true"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:layout_marginBottom="94dp"
        android:src="@drawable/es" />

    <Button
        android:id="@+id/enviar"
        android:onClick="resultado"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginHorizontal="@dimen/margemLateral"
        android:layout_marginBottom="28dp"
        android:text="enviar" />

    <RadioGroup
        android:id="@+id/radio1"
        android:layout_width="@dimen/radio"
        android:layout_height="@dimen/altura"
        android:layout_alignTop="@+id/imageTO"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="10dp"
        android:layout_marginHorizontal="@dimen/margemImagem">

        <RadioButton
            android:id="@+id/matoSul"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Mato Grossso do Sul" />

        <RadioButton
            android:id="@+id/tocantins"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Tocantins" />

        <RadioButton
            android:id="@+id/pernambuco"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Pernambuco" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/radio2"
        android:layout_width="@dimen/radio"
        android:layout_height="@dimen/altura"
        android:layout_marginHorizontal="@dimen/margemImagem"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="10dp"
        android:layout_alignTop="@+id/imageSP">

        <RadioButton
            android:id="@+id/saoPaulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="São Paulo" />

        <RadioButton
            android:id="@+id/piaui"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Piauí" />

        <RadioButton
            android:id="@+id/rioNorte"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Rio Grande do Norte" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/radio3"
        android:layout_width="@dimen/radio"
        android:layout_height="@dimen/altura"
        android:layout_marginHorizontal="@dimen/margemImagem"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="10dp"
        android:layout_alignTop="@+id/imagePA" >

        <RadioButton
            android:id="@+id/amazonas"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Amazonas" />

        <RadioButton
            android:id="@+id/roraima"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Roraima" />

        <RadioButton
            android:id="@+id/paraiba"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Paraíba" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/radio4"
        android:layout_width="@dimen/radio"
        android:layout_height="@dimen/altura"
        android:layout_marginHorizontal="@dimen/margemImagem"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="10dp"
        android:layout_alignTop="@+id/imageES" >

        <RadioButton
            android:id="@+id/santaCatarina"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Santa Catarina" />

        <RadioButton
            android:id="@+id/espiritoSanto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Espírito Santo" />

        <RadioButton
            android:id="@+id/alagoas"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Alagoas" />
    </RadioGroup>

</RelativeLayout>

Main2activity:

package sqlite.studio.com.identifique;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class Main2Activity extends Activity {

    private TextView texto;
    private Button botao;
    private int pontos;
    private RadioButton sp, to, pa, es;

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

        Bundle extra = getIntent().getExtras();
        texto = (TextView) findViewById(R.id.textoSaida);
        botao = (Button) findViewById(R.id.enviar);
        sp = (RadioButton) findViewById(R.id.saoPaulo);
        to = (RadioButton) findViewById(R.id.tocantins);
        es = (RadioButton) findViewById(R.id.espiritoSanto);
        pa = (RadioButton) findViewById(R.id.paraiba);

        if(extra != null){
            String nome = (String) extra.get("nomeUsuario");
            String mensagem = nome + texto.getText().toString();

            texto.setText(mensagem);
        }
    }

    public void resultado(View v){
        pontos = 0;
        onRadioButtonClicked(v);
        AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
        alert.setTitle("RESULTADO");
        alert.setMessage(pontos + "/4 acertos");
        alert.setNeutralButton("OK", null);
        alert.show();
    }

    public void onRadioButtonClicked(View v) {

        if(sp.isChecked()){
            pontos++;
        }

        if(es.isChecked()){
            pontos++;
        }

        if(to.isChecked()){
            pontos++;
        }

        if(pa.isChecked()){
            pontos++;
        }
    }
}
  • Look at the logcat and see if any error appears while running the application

  • I took a look at it, but could not identify the causes. I edited the question with the errors presented

  • Do you happen to have any images in your layout? Very large images can make it happen.

  • Edited, everyone, thank you for your attention. Leonardo, I believe that is not image size, I modified before editing and maintained the problem, and that on my teacher’s phone worked normally...

  • A possible solution in English

1 answer

0


If code contains no errors. Take this: When creating an app keep in mind Android versions and the API. In compensation Android lets you add in java or xml a type dependency type only does this if android is API 24 or higher. When one application works in one company not another it is because the other does not have the resource that the first has.

  • Thanks! The solution found was to add the attributes android:hardwareAccelerated="false" , android:largeHeap="true" in the manifest

Browser other questions tagged

You are not signed in. Login or sign up in order to post.