【发布时间】:2019-04-22 11:29:49
【问题描述】:
我在我的应用程序中编辑了文本来操纵产品数量,但是如果我要更改数量,那么问题是在那个时候获得 NPE。要更改编辑文本中的数量,我需要删除现有的并需要添加一个新的,请检查以下代码
viewHolder.edt_product_qty.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
quantity_count= Integer.parseInt(viewHolder.edt_product_qty.getText().toString());
buyNowList(user_id,"UserCart",0,stList.get(position).getCartList1().getId(),stList.get(position).getCartList1().getProdSku(),stList.get(position).getCartList1().getProdId(),quantity_count,0,qty_status,stList.get(position).getCartList1().getProdPrice());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
【问题讨论】:
-
请分享您的完整代码和您的错误,这是适配器吗?
-
是的,这是适配器..我正在使用 edittext 值来调用我的 api..so 来更改数量,它变得空并给出 NPE
-
分享你的适配器代码完成!!!
-
为什么不捕捉 Integer.parseInt 的 NumberFormatException 呢?如果 edt_product_qty 中没有数字(例如,当用户删除所有文本时),您的应用将崩溃。
标签: android android-edittext android-textwatcher