i have a problem, code run till half showing error, this is the delete function at **arrayList.remove(which_item);**
this line have problem showing
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.remove(int)' on a null object reference
Can someone tell what happen to this?
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final int which_item = position;
new AlertDialog.Builder(addProduct.this)
.setIcon(android.R.drawable.ic_delete)
.setTitle("Are you sure?")
.setMessage("Do you want to delete this item")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
**arrayList.remove(which_item);**
adapter.notifyDataSetChanged();
}
})
.setNegativeButton("No",null)
.show();
return true;
}
});
The function
onClick
does not know thewhich_item
, shouldn't it bewhich
.