if ((object.getString("MainCategoryID")).equals("3")
&& (object.getString("SubCategoryID")).equals("5")) {
Log.i("ImageURL ", object.getString("ImageURL"));
imageUrls.add(object.getString("ImageURL"));
Log.i("Description ", object.getString("Description"));
descriptions.add(object.getString("Description"));
Log.i("Price ", object.getString("Price"));
price.add(object.getString("Price"));
}
实际上价格是十进制值,但我将其作为字符串传递给下一个 Activity 。它 recives 为,
String price = getIntent().getStringExtra("price");
然后我使用该字符串值来计算小计,如下所示,
String quantity = quantityET.getText().toString();
double subTotal = 0;
subTotal += price * quantity;
但我收到此错误,操作符 * 未定义参数类型 java.lang.String、java.lang.String。我知道为什么会出现此错误,但我不知道如何在不使用字符串的情况下在 fragment 之间传递和检索数据。
我需要一些帮助来将所有字符串值转换为整数或帮助我解决这个问题。任何帮助,将不胜感激。
最佳答案
替换你的代码行
subTotal += price * quantity;
使用此代码
subTotal += (Double.parseDouble(price)) * (Double.parseDouble(quantity));
关于java - 使用 getIntent() 时 int 和 string 之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28535565/