- Forum posts: 1
Nov 21, 2015, 5:09:12 AM via Website
Nov 21, 2015 5:09:12 AM via Website
This is my code below it complies properly and when i click on the calculate button the app crashes i dont understand y?????
package thumbplay.tip;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class tip extends Activity {
double tbill;
double tippercent;
double tip_cal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tip);
final EditText billamt = (EditText) findViewById(R.id.tbill);
// final EditText tip=(EditText)findViewById(R.id.tpercent);
final EditText tip_percent = (EditText) findViewById(R.id.tpercent);
final TextView totalbill = (TextView) findViewById(R.id.gt);
//final TextView tipamount=(TextView)findViewById(R.id.tipamount);
//final TextView hpays=(TextView)findViewById(R.id.hpays);
final Button calculate = (Button) findViewById(R.id.caculate);
calculate.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tbill = Double.parseDouble(billamt.toString());
tippercent = Double.parseDouble(tip_percent.toString());
tip_cal = (tbill * tippercent) / 100;
totalbill.setText(Double.toString(tip_cal));
}
}
);
}
}