简体   繁体   English

Android Studio无法解析符号

[英]Android Studio Cannot resolve symbol

I am a beginner trying to lean android development, so I am taking google's android for beginner course, i have followed all the instructions but I get the error "Cannot resolve symbol price" in : displayMessage(createOrderSummary(price)); 我是一个尝试学习android开发的初学者,所以我将google的android用于初学者课程,我已经按照所有说明操作,但是在以下消息中收到错误“无法解析符号价格”:displayMessage(createOrderSummary(price));

This is part of the code ... 这是代码的一部分...

/**
 * 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;
}

Replace: 更换:

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

With: 带有:

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

The crux of the issue appears to be that price shouldn't be placed between asterisks. 问题的症结在于price不应放在星号之间。

Also, whilst it isn't essential to swap int Price for int price , it is common convention in Android to make variable names (like price ) lower case for their first character, and reserve upper-case first characters (ie Price ) for class names. 此外,虽然不必将int Price换成int Price int price ,但Android中的惯例是将变量名(如price )的首字符改成小写,并为类保留大写的首字符(即Price )。名称。

You are referencing a variable which does not exist. 您引用的变量不存在。 Variable names should start with a lowercase letter, so instead of Price , use price : 变量名必须以小写字母开头,所以不是Price ,用price

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

Also note that Java is case-sensitive, so if you name something price , you can't refer to it by Price . 另请注意,Java区分大小写,因此,如果您命名price ,则不能使用Price来引用它。 The names of classes (types) should start with a capital letter though. 但是,类(类型)的名称应以大写字母开头。

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

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