我在java.lang.NumberFormatException中出错:对于输入字符串:"null" [英] I got error in java.lang.NumberFormatException: For input string: "null"
问题描述
我在我的应用程序中的编辑购物车项目中出现错误.错误是: java.lang.NumberFormatException:对于输入字符串:"null"
.i事物错误行 interget.parseInt(" + v.getTag());
i have error in edit cart item in my app.the error is : java.lang.NumberFormatException: For input string: "null"
.i thing error line interget.parseInt("" + v.getTag());
我的代码:
case R.id.iv_edit_cart_item:
FragmentManager fm=getActivity().getSupportFragmentManager();
Fragment fragment = new ProductDetailActivity();
Bundle bundle = new Bundle();
int updatePos = Integer.parseInt("" + v.getTag());
bundle.putString("key","update");
bundle.putString("product_id", mArrListMyCart.get(updatePos).getmStrProductId());
bundle.putString("item_id", mArrListMyCart.get(updatePos).getmStrItemId());
getUpdateCartItems();
//showAlert("Product id-->" + mArrListMyCart.get(Integer.parseInt(""+v.getTag())).getmStrProductId(), -1);
fragment.setArguments(bundle);
fm.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack("").commit();
break;
如何解决这个问题?
推荐答案
当您尝试将非数字 String
解析为任意类型时,会出现 java.lang.NumberFormatException
像 Integer
或 Double
这样的数字.
The java.lang.NumberFormatException
comes when you try to parse a non-numeric String
to any Number like Integer
or Double
.
例如,如果您尝试将"null"
转换为 integer
,则将得到 NumberFormatException
.
For example, if you try to convert "null"
to an integer
then you will get NumberFormatException
.
错误线程主"中的异常" java.lang.NumberFormatException:
对于输入字符串:"null"专门表示您要解析的字符串不是数字.
The error "Exception in thread "main" java.lang.NumberFormatException:
For input string: "null" is specifically saying that the String you receive for parsing is not numeric.
在解析之前,请确保 v.getTag()
不为空.
Please ensure v.getTag()
is not null before parsing.
String input = v.getTag();
If( null != input )
{
int updatePos = Integer.parseInt("" + input);
}
这篇关于我在java.lang.NumberFormatException中出错:对于输入字符串:"null"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!