My main activity
public void removefunction(){
List<CartItem> cartItems = getCartItems(cart);
cart.remove(cartItems.get(position).getProduct());
cartItems.remove(position);
cartItemAdapter.updateCartItems(getCartItems(cart));
cartItemAdapter.notifyDataSetChanged();
tvTotalPrice.setText(Constant.CURRENCY+String.valueOf(cart.getTotalPrice().setScale(2, BigDecimal.ROUND_HALF_UP)));
}
Adapter code
btnremove= (Button) convertView.findViewById(R.id.btnrem);
btnremove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ShoppingCartActivity) context).removefunction();
}
});
Cause null pointer exception in tvTotalPrice.setText
FATAL EXCEPTION: main Process: com.android.tonyvu.sc.demo, PID: 7601 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.android.tonyvu.sc.demo.ShoppingCartActivity.removefunction(ShoppingCartActivity.java:263) at com.android.tonyvu.sc.demo.adapter.CartItemAdapter$1.onClick(CartItemAdapter.java:98) at android.view.View.performClick(View.java:6205) at android.widget.TextView.performClick(TextView.java:11103)