Android Studio: Use two SetOnClickListener in the MainActivity : I am developing an Android app. The topic is a cost manager.
I want to use two SetOnClickListener in the mainactivity for two buttons.
The first button change the view to a secound page (activity). And on this page there is a secound button, which just print out an log message.
But the app break down and do not throw an error message. The failure has to be in the secound onClickListener, because without it, it works.
Here is my sourcecode. Please help me.


   


public class MainActivity extends AppCompatActivity {

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

        // Init all Elements
        Button btn_hinzufügen = (Button) findViewById(R.id.btn_add);
        Button btn_speichern = (Button) findViewById(R.id.btn_speichern);



        btn_hinzufügen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                open_add_data();

            }
        });

    btn_speichern.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("Info", "Say Hello");
        }
    });
    }


    public void open_add_data() {
        setContentView(R.layout.add_data);
    }
}