1

Cuando ejecuto la aplicación en el emulador y en mi dispositivo físico, la aplicación se abre y se cierra al instante, aparece "La aplicación continua fallando"/"La aplicación dejo de funcionar" y pensé que era porque tenia el abstract en el public class MainActivity, pero tampoco funciono. En un principio, la aplicación funcionaba bien, tenia mis botones switch y el sharedpreference para guardarlos, pero cuando intente poner un segundo Activity, la aplicación empezó a presentar este problema.

Les dejo mi logcat:

Process: xyz.devleen.administradordetareas1, PID: 18701
    java.lang.RuntimeException: Unable to start activity ComponentInfo{xyz.devleen.administradordetareas1/xyz.devleen.administradordetareas1.MainActivity}: android.view.InflateException: Binary XML file line #281 in xyz.devleen.administradordetareas1:layout/main_activity: Binary XML file line #281: You must supply a layout_width attribute.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
     Caused by: android.view.InflateException: Binary XML file line #281 in xyz.devleen.administradordetareas1:layout/main_activity: Binary XML file line #281: You must supply a layout_width attribute.
     Caused by: java.lang.UnsupportedOperationException: Binary XML file line #281: You must supply a layout_width attribute.
        at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:830)
        at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:8231)
        at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:8429)
        at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:2023)
        at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1917)
        at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:89)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at xyz.devleen.administradordetareas1.MainActivity.onCreate(MainActivity.java:26)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3403)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)

Y mi main activity:

package xyz.devleen.administradordetareas1;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;


public abstract class MainActivity extends AppCompatActivity {

   TextView tvBoton;
   private Switch quim, fil, fis, tri, esp, engl, inf, eti, reli, est, pol, dib, edf, mate;
   private SharedPreferences sharedPreferences, sharfil, sharquim, shardfis, shartrig, sharesp, sharemate, sharing, sharinf, shareti, sharrel, sharest, sharpol, sharedf;
   public static final String ex1 = "switch1";
   public static final String ex = "switch";


   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main_activity);
       dib = (Switch) findViewById(R.id.switch1);
       sharedPreferences = getSharedPreferences("dib", MODE_PRIVATE);
       final SharedPreferences.Editor editor = sharedPreferences.edit();
       dib.setChecked(sharedPreferences.getBoolean(ex, false));
       dib.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
               if (isChecked) {
                   editor.putBoolean(ex, true);
               } else {
                   editor.putBoolean(ex, false);
               }
               editor.commit();
           }
       });

       fil = (Switch) findViewById(R.id.switch24);
       sharfil = getSharedPreferences("fil", MODE_PRIVATE);
       final SharedPreferences.Editor editorr = sharfil.edit();
       fil.setChecked(sharfil.getBoolean(ex, false));
       fil.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean issyChecked) {
               if (issyChecked) {
                   editorr.putBoolean(ex, true);
               } else {
                   editorr.putBoolean(ex, false);
               }
               editorr.commit();
           }
       });
       esp = (Switch) findViewById(R.id.switch2);
       sharesp = getSharedPreferences("esp", MODE_PRIVATE);
       final SharedPreferences.Editor editoresp = sharesp.edit();
       esp.setChecked(sharesp.getBoolean(ex, false));
       esp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isespChecked) {
               if (isespChecked) {
                   editoresp.putBoolean(ex, true);
               } else {
                   editoresp.putBoolean(ex, false);
               }
               editoresp.commit();
           }
       });

       quim = (Switch) findViewById(R.id.switch21);
       sharquim = getSharedPreferences("quim", MODE_PRIVATE);
       final SharedPreferences.Editor editorrr = sharquim.edit();
       quim.setChecked(sharquim.getBoolean(ex, false));
       quim.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isssChecked) {
               if (isssChecked) {
                   editorrr.putBoolean(ex, true);
               } else {
                   editorrr.putBoolean(ex, false);
               }
               editorrr.commit();
           }
       });

       fis = (Switch) findViewById(R.id.switch22);
       shardfis = getSharedPreferences("fis", MODE_PRIVATE);
       final SharedPreferences.Editor editor1 = shardfis.edit();
       fis.setChecked(shardfis.getBoolean(ex, false));
       fis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean iscChecked) {
               if (iscChecked) {
                   editor1.putBoolean(ex, true);
               } else {
                   editor1.putBoolean(ex, false);
               }
               editor1.commit();
           }
       });

       tri = (Switch) findViewById(R.id.switch6);
       shartrig = getSharedPreferences("tri", MODE_PRIVATE);
       final SharedPreferences.Editor editoru = shartrig.edit();
       tri.setChecked(shartrig.getBoolean(ex, false));
       tri.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isxChecked) {
               if (isxChecked) {
                   editoru.putBoolean(ex, true);
               } else {
                   editoru.putBoolean(ex, false);
               }
               editoru.commit();
           }
       });


       engl = (Switch) findViewById(R.id.switch25);
       sharing = getSharedPreferences("engl", MODE_PRIVATE);
       final SharedPreferences.Editor editort = sharing.edit();
       engl.setChecked(sharing.getBoolean(ex, false));
       engl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean iseChecked) {
               if (iseChecked) {
                   editort.putBoolean(ex, true);
               } else {
                   editort.putBoolean(ex, false);
               }
               editort.commit();
           }
       });

       inf = (Switch) findViewById(R.id.switch19);
       sharinf = getSharedPreferences("inf", MODE_PRIVATE);
       final SharedPreferences.Editor editorc = sharinf.edit();
       inf.setChecked(sharinf.getBoolean(ex, false));
       inf.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isinChecked) {
               if (isinChecked) {
                   editorc.putBoolean(ex, true);
               } else {
                   editorc.putBoolean(ex, false);
               }
               editorc.commit();
           }
       });

       edf = (Switch) findViewById(R.id.switch11);
       sharedf = getSharedPreferences("edf", MODE_PRIVATE);
       final SharedPreferences.Editor editoredf = sharedf.edit();
       edf.setChecked(sharedf.getBoolean(ex, false));
       edf.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isedfChecked) {
               if (isedfChecked) {
                   editoredf.putBoolean(ex, true);
               } else {
                   editoredf.putBoolean(ex, false);
               }
               editoredf.commit();
           }
       });

       reli = (Switch) findViewById(R.id.switch26);
       sharrel = getSharedPreferences("reli", MODE_PRIVATE);
       final SharedPreferences.Editor editorrel = sharrel.edit();
       reli.setChecked(sharrel.getBoolean(ex, false));
       reli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isrelChecked) {
               if (isrelChecked) {
                   editorrel.putBoolean(ex, true);
               } else {
                   editorrel.putBoolean(ex, false);
               }
               editorrel.commit();
           }
       });

       est = (Switch) findViewById(R.id.switch23);
       sharest = getSharedPreferences("est", MODE_PRIVATE);
       final SharedPreferences.Editor editorest = sharest.edit();
       est.setChecked(sharest.getBoolean(ex, false));
       est.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isestChecked) {
               if (isestChecked) {
                   editorest.putBoolean(ex, true);
               } else {
                   editorest.putBoolean(ex, false);
               }
               editorest.commit();
           }
       });

       pol = (Switch) findViewById(R.id.switch18);
       sharpol = getSharedPreferences("pol", MODE_PRIVATE);
       final SharedPreferences.Editor editorpol = sharpol.edit();
       pol.setChecked(sharpol.getBoolean(ex, false));
       pol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean ispolChecked) {
               if (ispolChecked) {
                   editorpol.putBoolean(ex, true);
               } else {
                   editorpol.putBoolean(ex, false);
               }
               editorpol.commit();
           }
       });

       eti = (Switch) findViewById(R.id.switch20);
       shareti = getSharedPreferences("eti", MODE_PRIVATE);
       final SharedPreferences.Editor editoreti = shareti.edit();
       eti.setChecked(shareti.getBoolean(ex, false));
       eti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isetiChecked) {
               if (isetiChecked) {
                   editoreti.putBoolean(ex, true);
               } else {
                   editoreti.putBoolean(ex, false);
               }
               editoreti.commit();
           }
       });
       mate = (Switch) findViewById(R.id.switch17);
       sharemate = getSharedPreferences("mate", MODE_PRIVATE);
       final SharedPreferences.Editor editormate = sharemate.edit();
       mate.setChecked(sharemate.getBoolean(ex, false));
       mate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean ismateChecked) {
               if (ismateChecked) {
                   editormate.putBoolean(ex1, true);
               } else {
                   editormate.putBoolean(ex1, false);
               }
               editormate.commit();
           }
       });

       tvBoton = (TextView) findViewById(R.id.Horario);
       tvBoton.setOnClickListener(new View.OnClickListener() {
           @Override
               public void onClick(View v) {
                   Intent i = new Intent(MainActivity.this, xyz.devleen.administradordetareas1.orario.class);
                   startActivity(i);
               }
           });
   }
}
1
  • Si lees el error te está diciendo exactamente qué falla....: Binary XML file line #281: You must supply a layout_width attribute Es decir, no has puesto layout_width al xml del layout de tu segunda activity. Te recomiendo encarecidamente leer las trazas de error con cuidado y no asustarte al verlos... pues por regla general suelen indicar con bastante exactitud cual es el problema!
    – Benito-B
    el 27 mar. 2021 a las 22:04

1 respuesta 1

0

Revisa el error:

Caused by: android.view.InflateException: Binary XML file line #281 in xyz.devleen.administradordetareas1:layout/main_activity: Binary XML file line #281: You must supply a layout_width attribute.

En tu archivo main_activity.xml no estas definendo el atributo layout_width, definelo como:

layout_width="match_parent"

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.