Jump to content
Android Forum - A Community For Android Users and Enthusiasts

NumberFormatException when I try to parseInt() from a String out of a number-only EditText


JordanRulz
 Share

Recommended Posts

this happens when i try to parseint from a String out of a numberonly EditText:

03-19 04:39:34.597: E/AndroidRuntime(339): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

03-19 04:39:34.597: E/AndroidRuntime(339): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)

03-19 04:39:34.597: E/AndroidRuntime(339): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

03-19 04:39:34.597: E/AndroidRuntime(339): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.os.Handler.dispatchMessage(Handler.java:99)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.os.Looper.loop(Looper.java:123)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.app.ActivityThread.main(ActivityThread.java:4363)

03-19 04:39:34.597: E/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)

03-19 04:39:34.597: E/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:521)

03-19 04:39:34.597: E/AndroidRuntime(339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

03-19 04:39:34.597: E/AndroidRuntime(339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

03-19 04:39:34.597: E/AndroidRuntime(339): at dalvik.system.NativeStart.main(Native Method)

03-19 04:39:34.597: E/AndroidRuntime(339): Caused by: java.lang.reflect.InvocationTargetException

03-19 04:39:34.597: E/AndroidRuntime(339): at org.jordanrulz.robotdriver.RobotDriver.connectrobot(RobotDriver.java:45)

03-19 04:39:34.597: E/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)

03-19 04:39:34.597: E/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:521)

03-19 04:39:34.597: E/AndroidRuntime(339): at android.view.View$1.onClick(View.java:2026)

03-19 04:39:34.597: E/AndroidRuntime(339): ... 22 more

03-19 04:39:34.597: E/AndroidRuntime(339): Caused by: java.lang.NullPointerException

03-19 04:39:34.597: E/AndroidRuntime(339): ... 26 more

Link to comment
Share on other sites

all my code you need to know:

public void connectrobot(View v) throws NullPointerException{
 String robotip1 = robotip.toString();
 String robotport1 = robotport.toString();
 try {
 robotport2 = Integer.parseInt(robotport1);
 }
 catch (NumberFormatException e2) {
  Log.i("NumberFormatException: " ,e2.getMessage());
 }
 try {
  robotip2 = InetAddress.getByName(robotip1);
 } catch (UnknownHostException e1) {
  // TODO Auto-generated catch block
  conerror.makeText(this, "Error connecting: " + e1.getMessage(), 2);
  conerror.show();
 }
 try {
  robotcon = new Socket(robotip2,robotport2);
 } catch (Exception e) {
  // TODO Auto-generated catch block
  conerror.makeText(this, "Error connecting: " + e.getMessage(), 2);
  conerror.show();


 }

conerror is a Toast

robotip is a text EditText

robotport is a numberonly EditText

this is for a robot i need to make for a school project

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...