【发布时间】:2018-12-16 20:45:21
【问题描述】:
我正在尝试将我的Cartadapter 的值传递给CartActivity。
我的代码如下:
CartActivity.java:
cartTotalChanged((cartAdapter.getTotal()));
CartAdapter.java:
public Double getTotal() {
Double total = 0d;
try{
for (MenuItem item : dataList)
total += item.getTotal();
}
catch(Exception e){
return total;
}
finally{
return total;
}
}
cartTotalChanged 函数:
public void cartTotalChanged(Double totalAmount) {
if (coupon != null) {
totalAmount = totalAmount - (coupon.getType().equals("fixed") ? coupon.getReward() : ((totalAmount * coupon.getReward()) / 100));
}
DecimalFormat decimalFormat = new DecimalFormat("###.##");
subtotal.setText(decimalFormat.format(totalAmount) + currency);
double sc = (totalAmount * serviceCharge / 100);
feeService.setText(decimalFormat.format(sc) + currency);
total.setText(decimalFormat.format(totalAmount > 0 ? (totalAmount + sc + deliveryFee) : 0) + currency);
Helper.setCart(sharedPreferenceUtil, cartItems);
}
我的问题是 cartTotalChanged((cartAdapter.getTotal())); 返回一个 Null 并且我的应用程序因多线程故障而崩溃。
请帮忙
【问题讨论】:
-
欢迎来到 Stack Overflow!看起来您可能需要学习使用调试器。请帮助自己一些complementary debugging techniques。如果之后您仍有问题,请edit您的问题更具体地说明您需要什么帮助。
-
你能显示堆栈跟踪吗?
标签: java android android-studio android-intent