I have made an basic deposit amount calculating application, where user can enter amount and tenure in months then he clicks on calculate button then app should show intrest value to the user. If i build this project at android studio using below said code. Application installs and opens on device but when it is clicked on button, Application will closes automatically. I am not understanding whether fault is in below code or device.
EditText et1,et2;
TextView mv,ie;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
mv=(TextView)findViewById(R.id.mv);
ie=(TextView)findViewById(R.id.ie);
}
public void Cumlative(View v){
float depositamt = Integer.parseInt(et1.getText().toString());
float tenure = Integer.parseInt(et2.getText().toString());
float matval = (float)((depositamt*tenure)/100);
ie.setText((int) matval);
}
Below is xml file
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Deposit Amount"
android:id="@+id/et1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Tenure in Months"
android:id="@+id/et2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cumlative"
android:textStyle="bold"
android:textColor="#8BC34A"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Maturity value"
android:id="@+id/mv"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Intrest earned"
android:id="@+id/ie"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:layout_gravity="center"
android:id="@+id/cal"
android:onClick="Cumlative"/>
log:
11-15 20:59:08.102 15074-15074/? I/fpc_tac: Returning from transfer command 0x24;3028
11-15 20:59:08.102 15074-15074/? I/fpc_tac: <--_fpc_tac_transfer_data returns tlTci->rsp.cmd_ret;3040
11-15 20:59:08.102 15074-15074/? I/fpc_tac: Enter _fpc_tac_load_database_id;2325
11-15 20:59:08.102 15074-15074/? I/fpc_tac: _fpc_tac_load_database_id, random_id_size, 96;2349
11-15 20:59:08.102 15074-15074/? I/fpc_tac: -->_fpc_tac_transfer_data command 0x29;2866
11-15 20:59:08.102 15074-15074/? I/fpc_tac: -->_fpc_tac_send_cmd command 0x02,0x29;2677
First of all, please provide the error that shows in your logcat for us to easily identify your error. Second of all, the error is on this two lines:
float depositamt = Integer.parseInt(et1.getText().toString());
float tenure = Integer.parseInt(et2.getText().toString());
Change them to
float depositamt = Float.parseFloat(et1.getText().toString());
float tenure = Float.parseFloat(et2.getText().toString());