我正在尝试获取用户在EditText
中输入的整数值。解析Android中的整数值
EditText eTextValue=(EditText) findViewById(R.id.eId);
String eTextString=eTextValue.getText().toString();
int eTextValue1=Integer.parseInt(eTextString);
但偏偏我得到,
无法分析9827328为整数。
我试过使用Integer.valueOf
而不是Integer.parseInt
但我再次遇到同样的异常。
我甚至已经使用Long
类型来存储值,而不是int
类型的数据类型,但似乎没有要working.Any帮助在此将得到高度赞赏。 我已经通过所有这些链接unable to parse ' ' as integer in android,Parsing value from EditText ...但似乎没有任何工作,他们都在登陆我的例外。
您可以发布您的异常堆栈跟踪? – Srinivas
您输入的号码可能有前导空格和/或尾随空格。尝试使用'trim()'方法。 – Lion
使用android:inputType =“number”在xml中试试。另请参阅.. http://stackoverflow.com/questions/4903515/how-do-i-return-an-int-from-edittext-android http://stackoverflow.com/questions/2709253/converting-a-string-to-an-integer-android – ridoy