Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

用命令行对javac进行编译,总是『cannot find symbol』,但是eclipse执行不会出现问题

代码如下
分别是enum和testclass两个java文件

package cs121assignment1;

public enum Food {
    APPLE("fruit", 55),
    BANANA("fruit", 80),
    CARROT("vegetable", 60);
    
    private final String catagory; //vegetable or fruit
    private final int calorie;
    
    Food(String catagory, int calorie){
        this.catagory = catagory;
        this.calorie = calorie;
    }
    
    public int getCalorie(){
        return calorie;
    }
    
    public String getCatagory(){
        return catagory;
    }
}
package cs121assignment1;

public class TestFood {

public static void main(String[] args){
    System.out.println("All foods:");
    
    for(Food food : Food.values()){
        System.out.printf("%s, catagory: %s, calorie: %d kilocalorie each
", food, food.getCatagory(), food.getCalorie());
    }
        
}

eclipse中运行结果如下:图片描述

但是用命令行执行javac的时候显示如下:

图片描述


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

cd Desktop;
javac cs121assignment1.TestFood;

不要
cd Desktop/cs121assignment1;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...