I'm writing new accounting program for my customer on Android,In some case I need to convert text of EditText to integer,but when I want to parse "-1" the java.lang.NumberFormatException
occured!
for understanding my problem try this: int i = Integer.parseInt("-1");
Can anybody help me? Thank you!
this is code:
int i = Integer.parseInt("-1");
and this is log trace:
07-09 03:33:36.932: E/AndroidRuntime(925): at dalvik.system.NativeStart.main(Native Method)
07-09 03:36:09.252: E/AndroidRuntime(985): FATAL EXCEPTION: main
07-09 03:36:09.252: E/AndroidRuntime(985): java.lang.NumberFormatException: Invalid int: "-1
07-09 03:36:09.252: E/AndroidRuntime(985): "
07-09 03:36:09.252: E/AndroidRuntime(985): at java.lang.Integer.invalidInt(Integer.java:138)
07-09 03:36:09.252: E/AndroidRuntime(985): at java.lang.Integer.parse(Integer.java:375)
07-09 03:36:09.252: E/AndroidRuntime(985): at java.lang.Integer.parseInt(Integer.java:366)
07-09 03:36:09.252: E/AndroidRuntime(985): at java.lang.Integer.parseInt(Integer.java:332)
07-09 03:36:09.252: E/AndroidRuntime(985): at forms.FYH_moshtari.UpdateRow(FYH_moshtari.java:149)
07-09 03:36:09.252: E/AndroidRuntime(985): at yhesabyargui.YMaster_Body.OnAccept(YMaster_Body.java:61)
07-09 03:36:09.252: E/AndroidRuntime(985): at yhesabyargui.YMaster_Body$10.onClick(YMaster_Body.java:321)
07-09 03:36:09.252: E/AndroidRuntime(985): at yhesabyargui.CYH_Ctrl_ToolItem.onClick(CYH_Ctrl_ToolItem.java:111)
07-09 03:36:09.252: E/AndroidRuntime(985): at android.view.View.performClick(View.java:4240)
07-09 03:36:09.252: E/AndroidRuntime(985): at android.view.View$PerformClick.run(View.java:17721)
07-09 03:36:09.252: E/AndroidRuntime(985): at android.os.Handler.handleCallback(Handler.java:730)
07-09 03:36:09.252: E/AndroidRuntime(985): at android.os.Handler.dispatchMessage(Handler.java:92)
07-09 03:36:09.252: E/AndroidRuntime(985): at android.os.Looper.loop(Looper.java:137)
This is complete code:
public interface IYH_BodyControl {
void showError(String Caption);
void showHint(String Caption);
void setNormal();
String getValue();
void setValue(String Value);
void setEnable(Boolean Enable);
void setLabel(String Label);
void setVisible(Boolean Visible);
LinearLayout getFrame();
int getID();
Boolean ValidateForInsert();
Boolean ValidateForUpdate();
Boolean ValidateForDelete();
void ClearContent();
void Focus();
}
....
protected Hashtable<Integer, IYH_BodyControl> ctrls = new Hashtable<Integer, IYH_BodyControl>();
....
protected void InsertRow() {
tblmoshtari().setAddress(ctrls.get(ctrladdr).getValue());
tblmoshtari().setFname(ctrls.get(ctrlfname).getValue());
tblmoshtari().setFamily(ctrls.get(ctrlfamily).getValue());
tblmoshtari().setMobile(ctrls.get(ctrlmobile).getValue());
tblmoshtari().setTel(ctrls.get(ctrltel).getValue());
tblmoshtari().setMaxDebt(Integer.parseInt(ctrls.get(ctrlmaxdebt).getValue()));
tblmoshtari().Insert();
}
....
Is it clear?