Crash app when entering Landscape mode

Asked

Viewed 41 times

-1

My app has two layouts, a pro mode Portrait and another pro Landscape. When I assign an event to open another Activity to the screen button, when I turn the phone, (I put it in Landscape mode) the crasha app.If you don’t rotate the device, everything happens normally. What could be the reason for this?

Code of Activity crashing package com.example.Igor.olddog;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Button btn_calcular_idade;
EditText idade_cachorro;


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

    btn_calcular_idade = findViewById(R.id.btn_calcular_idade);
    idade_cachorro = findViewById(R.id.edit_caixa_texto);


    btn_calcular_idade.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent abrir_resultadoActivity = new Intent(MainActivity.this, ResultadoActivity.class);
            startActivity(abrir_resultadoActivity);
        }
    });
}

}

1 answer

1

The problem was that in the xml of Landscape mode btn had a different ID than it was in Portrait mode

Browser other questions tagged

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