Aft*_*Ali 4 java android exception-handling type-conversion
当我遇到这个问题时,我正在研究我的android项目
我希望这将像"0345303709"7这样的字符串转换为整数,但我不断得到NumberFormatException.
我在这里搜索了所有问题,但没有找到解决我问题的方法.
以下是我的Android代码:
String edit_cell=cellnumber.getText().toString();
try
{
if(cellnumber.getText().length()==11 && TextUtils.isEmpty(edit_cell)!=true && edit_cell!=null)
{
cell=Integer.valueOf("03462651882");
}
else
{
Toast.makeText(this, "Invalid CellNumber\n Write CellNumber like this Format:\nNetworkCode Followed by your Number\n",Toast.LENGTH_LONG).show();
Toast.makeText(this, "eg:03213213214",Toast.LENGTH_LONG).show();
}
}
catch(Exception ex)
{
Toast.makeText(this, "Invalid cellnumber\n Write cellNumber line this format:\n Network code followed by your number\n",Toast.LENGTH_LONG).show();
Toast.makeText(this, "eg:03213213214",Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
我使用的是eclipse Helios IDE和Android版本是2.2 api 8