Android app crashes after adding ButtonHandler?
Go to solution
Solved by Er0r,
package com.example.tejas.lttsub; 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.Toast; public class MainActivity extends AppCompatActivity { private Button submit_btn; private EditText name_txt; private EditText age_txt; private EditText height_txt; private EditText weight_txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setup_activity(); } private void setup_activity() { //set up on screeen controls submit_btn = findViewById(R.id.but); //assign handlers submit_btn.setOnClickListener(new ButtonHandler()); //runs fine without this line } private class ButtonHandler implements View.OnClickListener { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Working", Toast.LENGTH_SHORT).show(); submit_btn.setText("success"); } } }
I Re-Wrote your code and it seems to work fin Maybe your xml file is written a bit wrong.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now