I am getting problem with my application.it is crashing on pressing any of the button.
I have used float conversion of string object.
My MainActivity.java file:
package com.example.admin.myapplication;
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.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
TextView tv1,tv2;
EditText et1;
Button btn1,btn2,btn3,btn4;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=findViewById(R.id.tv1);
tv2=findViewById(R.id.tv2);
et1=findViewById(R.id.et1);
btn1=findViewById(R.id.btn1);
btn2=findViewById(R.id.btn2);
btn3=findViewById(R.id.btn3);
btn4=findViewById(R.id.btn4);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
btn4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
tv2.findViewById(R.id.tv2);
String value=et1.getText().toString();
int newvalue=Integer.parseInt(value);
int thirdvalue=0;
switch (v.getId()){
case R.id.btn1:
thirdvalue = (int) (newvalue*37.98f);
tv2.setText(thirdvalue);
break;
case R.id.btn2:
thirdvalue = (int) (newvalue*45.47f);
tv2.setText(thirdvalue);
break;
case R.id.btn3:
thirdvalue = (int) (newvalue*50.52f);
tv2.setText(thirdvalue);
break;
case R.id.btn4:
thirdvalue = (int) (newvalue*63.16f);
tv2.setText(thirdvalue);
break;
}
}
}
I want to get result on pressing any of the button and give result as per pressed button.
It is giving this error in my logcat:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.admin.myapplication, PID: 14892 android.content.res.Resources$NotFoundException: String resource ID #0x3b5 at android.content.res.Resources.getText(Resources.java:328) at android.content.res.MiuiResources.getText(MiuiResources.java:125) at android.widget.TextView.setText(TextView.java:4432) at com.example.admin.myapplication.MainActivity.onClick(MainActivity.java:45) at android.view.View.performClick(View.java:5215) at android.view.View$PerformClick.run(View.java:21196) at android.os.Handler.handleCallback(Handler.java:742) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5603) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) I/Process: Sending signal. PID: 14892 SIG: 9 Application terminated.