繁体   English   中英

Android Studio无法解析符号

[英]Android Studio Cannot resolve symbol

我是一个尝试学习android开发的初学者,所以我将google的android用于初学者课程,我已经按照所有说明操作,但是在以下消息中收到错误“无法解析符号价格”:displayMessage(createOrderSummary(price));

这是代码的一部分...

/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    int Price = calculatePrice();
    displayMessage(createOrderSummary(*price*));
        }


/**
 * Calculates the price of the order.
 *
 * @return total price
 */

public int calculatePrice() {
    return quantity * 5;
       }

/**
 *this method will create the order summary.
 *@param price of the order
 *@return text summary
*/

private String createOrderSummary (int price){
    String priceMessage = "Name: Ana";
    priceMessage +=  "\n Price;Quantity:" + quantity;
    priceMessage +=  "\nTotal $"+ price;
    priceMessage +=  "\n Thank You!";
    return priceMessage;
}

更换:

public void submitOrder(View view) {
    int Price = calculatePrice();
    displayMessage(createOrderSummary(*price*));
}

带有:

public void submitOrder(View view) {
    int price = calculatePrice();
    displayMessage(createOrderSummary(price));
}

问题的症结在于price不应放在星号之间。

此外,虽然不必将int Price换成int Price int price ,但Android中的惯例是将变量名(如price )的首字符改成小写,并为类保留大写的首字符(即Price )。名称。

您引用的变量不存在。 变量名必须以小写字母开头,所以不是Price ,用price

public void submitOrder(View view) {
    int price = calculatePrice();
    displayMessage(createOrderSummary(price));
}

另请注意,Java区分大小写,因此,如果您命名price ,则不能使用Price来引用它。 但是,类(类型)的名称应以大写字母开头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM