09-11 11:02:19.365: E/AndroidRuntime(1263): FATAL EXCEPTION: main 09-11 11:02:19.365: E/AndroidRuntime(1263): Process: com.nnk.program4, PID: 1263 09-11 11:02:19.365: E/AndroidRuntime(1263): java.lang.NumberFormatException: Invalid int: "+" 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.Integer.invalidInt(Integer.java:137) 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.Integer.parse(Integer.java:374) 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.Integer.parseInt(Integer.java:365) 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.Integer.parseInt(Integer.java:331) 09-11 11:02:19.365: E/AndroidRuntime(1263): at com.nnk.program4.Calc$1.onClick(Calc.java:40) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.view.View.performClick(View.java:4438) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.view.View$PerformClick.run(View.java:18422) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.os.Handler.handleCallback(Handler.java:733) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.os.Handler.dispatchMessage(Handler.java:95) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.os.Looper.loop(Looper.java:136) 09-11 11:02:19.365: E/AndroidRuntime(1263): at android.app.ActivityThread.main(ActivityThread.java:5017) 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.reflect.Method.invokeNative(Native Method) 09-11 11:02:19.365: E/AndroidRuntime(1263): at java.lang.reflect.Method.invoke(Method.java:515) 09-11 11:02:19.365: E/AndroidRuntime(1263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 09-11 11:02:19.365: E/AndroidRuntime(1263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 09-11 11:02:19.365: E/AndroidRuntime(1263): at dalvik.system.NativeStart.main(Native Method)
public class Calc extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.calc); this.myLogin(); } private EditText tx1,tx2,tx3; private Button b1; private TextView tv1; public void myLogin() { tx1 = (EditText)findViewById(R.id.editText1); tx2 = (EditText)findViewById(R.id.editText2); tx3 = (EditText)findViewById(R.id.editText3); b1 = (Button)findViewById(R.id.button1); tv1 =(TextView)findViewById(R.id.textView1); b1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int no1 = Integer.parseInt(tx1.getText().toString()); int no2 = Integer.parseInt(tx3.getText().toString()); System.out.println(no1+no2); String opt = tx2.getText().toString(); System.out.println(opt); if (opt.equals("+")) { tv1.setText("Result : "+(no1+no2)); } else { if (opt.equals("-")) { tv1.setText("Result : "+(no1-no2)); } else { if (opt.equals("*")) { tv1.setText("Result : "+(no1*no2)); } else { if (opt.equals("/")) { try { tv1.setText("Result : "+(no1/no2)); } catch (Exception e) { tv1.setText(e.getMessage()); } } else { tv1.setText("Sorry Wrong Operator"); } } } } } }); } }
Invalid int: "+"
Integer.parseInt
+
tx1
tx3
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)