i have problem in my coding in button part. On 3-5 Every time I try run my app after it loads the first page and I tap on the button to link it to the second page it crashes , it been driving me crazy. can anyone help me with my coding because whenever i click the button my app stuck and open another app. and this is android app studio.
my coding
package net.mobiledevelopment.paintcalculator;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Spinner;import android.widget.TextView;import java.text.DecimalFormat;public class MainActivity extends AppCompatActivity {double totalFeet,heightFeet,distanceFeet;double gallons;String color;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final EditText height = (EditText)findViewById(R.id.txtHeight);final Spinner colors = (Spinner)findViewById(R.id.spnColors);final EditText distance = (EditText)findViewById(R.id.txtDistance);Button btnCompute = (Button)findViewById(R.id.btnCompute);btnCompute.setOnClickListener(new View.OnClickListener() {final TextView result = ((TextView)findViewById(R.id.txtResult));@Overridepublic void onClick(View v) {heightFeet = Double.parseDouble(height.getText().toString());distanceFeet = Double.parseDouble(distance.getText().toString());totalFeet = heightFeet * distanceFeet;gallons = totalFeet/250;DecimalFormat gallon = new DecimalFormat( "## , ##");color = colors.getSelectedItem().toString();result.setText("Color: " + color + " in " + gallon.format(gallons) +"gallons");}});}}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here