"Backward arrow" button on the top ERROR Android Studio

0

In total there are 3 classes with their respective layout, but the error comes at the moment of returning from layout 3 to layout 2, I have added layout 2 and 3 with their classes:

CLASS 2:

    private Button siguiente2;
    private RadioButton opcionFarewell, opcionGreeter;
    private SeekBar barra;
    private TextView txtedad;

    private int edad=18;
    private String nombre="";
    private final int edad_max=60, edad_min=16;
    public static final int GREETER_OPTION=1;
    public static final int FIREWELL_OPTION=2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        nombre=getIntent().getExtras().getString("palabra");
        siguiente2=(Button)findViewById(R.id.btnsiguiente2);
        opcionFarewell=(RadioButton)findViewById(R.id.radio1);
        opcionGreeter=(RadioButton)findViewById(R.id.radio2);
        barra=(SeekBar)findViewById(R.id.seekBar);
        txtedad=(TextView)findViewById(R.id.textView2);

        barra.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                edad=progress;
                txtedad.setText(edad+"");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                edad=barra.getProgress();
                txtedad.setText(edad+"");
                if(edad>edad_max){
                    siguiente2.setVisibility(View.INVISIBLE);
                    Toast.makeText(SecondActivity.this, "La edad maxima es "+edad_max, Toast.LENGTH_SHORT).show();
                }else if(edad<edad_min){
                    siguiente2.setVisibility(View.INVISIBLE);
                    Toast.makeText(SecondActivity.this, "La edad minima es "+edad_min, Toast.LENGTH_SHORT).show();
                }else{
                    siguiente2.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    public void Siguiente2(View v){
        Intent intent=new Intent(SecondActivity.this, ThirdActivity.class);
        intent.putExtra("nombre", nombre);
        intent.putExtra("edad", edad);
        int opcion=(opcionGreeter.isChecked()) ? GREETER_OPTION : FIREWELL_OPTION;
        intent.putExtra("opcion", opcion);
        startActivity(intent);
        Toast.makeText(SecondActivity.this, "Tu edad es "+barra.getProgress(), Toast.LENGTH_SHORT).show();
    }

CLASS 3:

 private ImageButton btnconfirmar;
    private Button btncompartir;

    private String nombre="";
    private int edad=0;
    private int tipoMensaje=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        nombre=getIntent().getExtras().getString("nombre");
        edad=getIntent().getExtras().getInt("edad");
        tipoMensaje=getIntent().getExtras().getInt("opcion");
        btncompartir=(Button)findViewById(R.id.btnok);
        btnconfirmar=(ImageButton)findViewById(R.id.imageButton);
    }
private String crearMensaje(String nombre, int edad, int tipoMensaje){
    if(tipoMensaje==SecondActivity.GREETER_OPTION){
        return "Hola "+nombre+" Como vas con tus "+edad+" años?";
    }else{
        return "Espero verte pronto "+nombre+" antes de que cumplas "+(edad+1)+" !";
    }
}

public void Confirmar(View v){
    Toast.makeText(this,crearMensaje(nombre,edad,tipoMensaje),Toast.LENGTH_SHORT).show();
    btncompartir.setVisibility(View.VISIBLE);
    btnconfirmar.setVisibility(View.INVISIBLE);
}

public void Compartir(View v){
    Intent intent=new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT,crearMensaje(nombre,edad,tipoMensaje));
    startActivity(intent);
}

LAYOUT 2:

<Button
    android:id="@+id/btnsiguiente2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="@string/boton1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2"
    android:onClick="Siguiente2"/>


<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="198dp"
    android:layout_height="50dp"
    android:layout_marginBottom="44dp"
    app:layout_constraintBottom_toTopOf="@+id/textView2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/radioGroup"
    android:max="80"
    android:progress="18"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="76dp"
    android:text="@string/numero"
    app:layout_constraintBottom_toTopOf="@+id/btnsiguiente2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/seekBar"
    android:textSize="38sp"/>

<RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="54dp"
    android:layout_marginTop="45dp"
    android:layout_marginEnd="54dp"
    android:layout_marginBottom="69dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toTopOf="@+id/seekBar"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">


    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/opcion1" />

    <RadioButton
        android:id="@+id/radio2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="@string/opcion2" />
</RadioGroup>

LAYOUT 3:

<Button
    android:id="@+id/btnok"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:text="@string/boton2"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/imageButton"
    android:visibility="invisible"
    android:onClick="Compartir"/>

<ImageButton
    android:id="@+id/imageButton"
    android:layout_width="162dp"
    android:layout_height="0dp"
    android:layout_marginBottom="159dp"
    android:background="@color/colorPrimaryDark"
    app:layout_constraintBottom_toTopOf="@+id/btnok"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView3"
    app:srcCompat="@android:drawable/checkbox_on_background"
    android:onClick="Confirmar"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="96dp"
    android:layout_marginBottom="20dp"
    android:text="@string/texto2"
    android:textSize="25sp"
    app:layout_constraintBottom_toTopOf="@+id/imageButton"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

MANIFEST

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SecondActivity" android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>
    <activity android:name=".ThirdActivity" android:parentActivityName=".SecondActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".SecondActivity" />
    </activity>
</application>

In the Manifest, when you return from layout 2 to layout 1, everything is normal, but when you return from layout 3 to layout 2, I find that the application stopped. HELP! (I'm new to Android Studio)

This is the Logcast

10-03 14:18:11.230 15860-15860/com.example.jose.ejercicio3 D/AndroidRuntime: Shutting down VM
10-03 14:18:11.230 15860-15860/com.example.jose.ejercicio3 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.jose.ejercicio3, PID: 15860
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jose.ejercicio3/com.example.jose.ejercicio3.SecondActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
        at android.app.ActivityThread.access$1100(ActivityThread.java:221)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7224)
        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.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
        at com.example.jose.ejercicio3.SecondActivity.onCreate(SecondActivity.java:30)
        at android.app.Activity.performCreate(Activity.java:6876)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
        at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:158) 
        at android.app.ActivityThread.main(ActivityThread.java:7224) 
        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) 
10-03 14:18:14.260 15860-15860/com.example.jose.ejercicio3 I/Process: Sending signal. PID: 15860 SIG: 9
10-03 14:18:14.380 16117-16117/com.example.jose.ejercicio3 W/ResourcesManager: getTopLevelResources: /data/app/com.example.jose.ejercicio3-1/base.apk / 1.0 running in com.example.jose.ejercicio3 rsrc of package null
10-03 14:18:14.470 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.640 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.700 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.760 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.830 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.890 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:14.940 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:15.000 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:15.060 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:15.120 16117-16117/com.example.jose.ejercicio3 W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.example.jose.ejercicio3-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
10-03 14:18:15.120 16117-16117/com.example.jose.ejercicio3 W/System: ClassLoader referenced unknown path: /data/app/com.example.jose.ejercicio3-1/lib/arm
10-03 14:18:15.120 16117-16117/com.example.jose.ejercicio3 I/InstantRun: starting instant run server: is main process
10-03 14:18:15.200 16117-16117/com.example.jose.ejercicio3 W/ResourcesManager: getTopLevelResources: /data/app/com.example.jose.ejercicio3-1/base.apk / 1.0 running in com.example.jose.ejercicio3 rsrc of package null
10-03 14:18:15.200 16117-16117/com.example.jose.ejercicio3 W/ResourcesManager: getTopLevelResources: /data/app/com.example.jose.ejercicio3-1/base.apk / 1.0 running in com.example.jose.ejercicio3 rsrc of package null
10-03 14:18:15.230 16117-16117/com.example.jose.ejercicio3 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
10-03 14:18:15.390 16117-16117/com.example.jose.ejercicio3 D/TextView: setTypeface with style : 0
10-03 14:18:15.390 16117-16117/com.example.jose.ejercicio3 D/TextView: setTypeface with style : 0
10-03 14:18:15.460 16117-16117/com.example.jose.ejercicio3 D/TextView: setTypeface with style : 0
10-03 14:18:15.460 16117-16117/com.example.jose.ejercicio3 D/TextView: setTypeface with style : 0
10-03 14:18:15.470 16117-16117/com.example.jose.ejercicio3 D/TextView: setTypeface with style : 0
10-03 14:18:15.490 16117-16117/com.example.jose.ejercicio3 D/SecWifiDisplayUtil: Metadata value : none
10-03 14:18:15.490 16117-16117/com.example.jose.ejercicio3 D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{7ea0ea I.E...... R.....ID 0,0-0,0}
10-03 14:18:15.500 16117-16153/com.example.jose.ejercicio3 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-03 14:18:15.550 16117-16153/com.example.jose.ejercicio3 I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build:  (Ia10634f51b)
    OpenGL ES Shader Compiler Version: E031.29.00.00
    Build Date: 01/28/16 Thu
    Local Branch: ss
    Remote Branch: 
    Local Patches: 
    Reconstruct Branch: 
    
asked by Jrse 03.10.2018 в 07:44
source

1 answer

0

When you go to activities for example in the following way

Activity 1 - > Activity 2 - > Activity 3

You can use putExtras () to pass data from one to another, for example from Activity 1 to Activity 2

Intent intent = new Intent(Actividad1.this,Actividad2.class);
intent.putExtra("nombre","fred");
startActivity(intent);

from Activity 2 to 3 is the same, but now when you want to return and bring a result, it is not the same, because the flow of how you carry the data changes, for example, to carry data from Activity 3 at 2 you should use a startActivityForResult and use an onActivityResult in your Activity 2, which is where you will receive data from the 3.

I recommend you read this

link

and this video (although this one in English is easy to understand)

link

    
answered by 04.10.2018 в 04:09