Java 找不到符号…-爪哇
我是OOP概念的新手,我遇到了一个错误:找不到符号。在编译过程中,我还发现了两个错误:Java 找不到符号…-爪哇,java,oop,syntax-error,symbols,Java,Oop,Syntax Error,Symbols,我是OOP概念的新手,我遇到了一个错误:找不到符号。在编译过程中,我还发现了两个错误: Error:(9, 35) java: <identifier> expected Error:(9, 36) java: illegal start of type 你的代码 TestClass waterBottle = new TestClass(); waterBottle.bottleFill(5); 实际上位于类定义中 将此代码移动到您的main方法: public class M
Error:(9, 35) java: <identifier> expected
Error:(9, 36) java: illegal start of type
你的代码
TestClass waterBottle = new TestClass();
waterBottle.bottleFill(5);
实际上位于类定义中
将此代码移动到您的main
方法:
public class Main {
public static void main(String[] args) {
TestClass waterBottle = new waterBottle();
waterBottle.bottleFill(5);
}
}
当你正确地格式化你的代码时,这个问题就变得明显和明显了——使用标识、垂直和水平间距。我已经对你的问题进行了编辑,以便它现在的格式正确。看一看,注意它现在的可读性
另一个问题是类对象的创建。您在new waterBottle()
行提供的名称不正确<代码>新建后应加上正确的类名:
TestClass waterBottle = new TestClass();
你的文件名是什么?您的系统中是否安装了java。我相信您在CLI中遇到了错误。这两个类在不同的java文件中?
TestClass waterBottle = new TestClass();
package com.company;
public class Main {
public static void main(String[] args) {
//TestClass waterBottle = new waterBottle(); // what is waterbottle.. this will give you can not find symbol`
TestClass waterBottle = new TestClass();//should be this
waterBottle.bottleFill(5);
}// main method ends
}// class ends
package com.company;
public class TestClass {
TestClass(){}
public void waterBottleFill(int y){
int bottleFill = y;
System.out.println("Fill level is at:"+ bottleFill);
}
public void waterBottleRefill(int x){
int refill = x;
}
}