application crashes when entering landscape mode

-1

My app has two layouts, one pro portrait mode and the other pro landscape. When assigning an event to open another activity to the onscreen button, when I rotate the mobile, (I put it in landscape mode) crasha app. If you do not rotate the device, everything happens normally. What could be the reason for this?

activity code 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);
        }
    });
}

}

    
asked by anonymous 03.06.2018 / 04:56

1 answer

1

The problem was that in landscape mode xml btn was with a different ID than it was in portrait mode

    
03.06.2018 / 05:00