Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)



My Program

C#
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");	
							}
						}
					}
				}
			}
		});
	}
}
Posted
Updated 15-Sep-14 2:08am
v3
Comments
Richard Deeming 11-Sep-14 12:00pm    
Invalid int: "+"

You've typed "+" into a text box which is expecting a number.
Sergey Alexandrovich Kryukov 11-Sep-14 14:48pm    
Why not posting it as an answer? It's very unlikely that the problem can be attributed to anything else...
—SA

The exception message says: Invalid int: "+"

The stack-trace says it was generated by a call to Integer.parseInt.

That suggests that you've typed "+" into one of the text boxes in which you're expecting to find an integer - either tx1 or tx3.
 
Share this answer
 
Hi Richard Deeming

How to solve it
 
Share this answer
 
Comments
Richard MacCutchan 12-Sep-14 3:54am    
Don't post questions in the Solution boxes. use the "Have a Question or Comment?" button below the answer.
Member 11075535 12-Sep-14 6:38am    
sorry i am very new to this blog i dont no how to use it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900