我正在嘗試獲取用戶在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