Java.lang.ClassCastException错误和应用程序崩溃

时间:2020-04-21 17:15:49

标签: java android firebase android-fragments android-recyclerview

错误日志我被困在这里,我尝试了许多解决方案,但都存在相同的错误

java.lang.ClassCastException: com.beauty.fashion.style.KidsNavigationDrawerActivity cannot be cast to com.beauty.fashion.style.interfaces.UpdateOrderTotal
        at com.beauty.fashion.style.adapters.CheckoutAdapter.<init>(CheckoutAdapter.java:38)
        at com.beauty.fashion.style.fragment.OrderConfirmationFragment.onCreateView(OrderConfirmationFragment.java:109)

这是我的android代码


 public CheckoutAdapter(Context context, List<ProductModel> list) {

        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
        callback = (UpdateOrderTotal) context;  //This is line 38 of CheckoutAdapter
        helper = new FashionDbHelper(context);
        utils = new CartUtils(context);
    }

这是我将产品添加到购物车列表并且应用崩溃的地方

if (utils.getCartList().getValue() != null) {
            cartList.addAll(utils.getCartList().getValue());
            if (cartList != null && cartList.size() > 0) {
                linearEmptyCart.setVisibility(View.GONE);
                cvGrandTotal.setVisibility(View.VISIBLE);
                adapter = new CheckoutAdapter(getActivity(), cartList); //This is line 109 
                rvConfirmOrder.setAdapter(adapter);
                rvConfirmOrder.setLayoutManager(new LinearLayoutManager(getActivity()));
                calculateTotal(cartList);
            } else {
                linearEmptyCart.setVisibility(View.VISIBLE);
                cvGrandTotal.setVisibility(View.GONE);
            }
        } else {
            cvGrandTotal.setVisibility(View.GONE);
            linearEmptyCart.setVisibility(View.VISIBLE);
        }

2 个答案:

答案 0 :(得分:0)

您需要KidsNavigationDrawerActivity来实现UpdateOrderTotal接口。

类似这样的东西:

public class KidsNavigationDrawerActivity extends AppCompatActivity implements UpdateOrderTotal {

// your Activity code here

}

答案 1 :(得分:-1)

在实现了KidsNavigationDrawer活动的接口之后,我自己完成了操作

相关问题