【发布时间】:2017-08-14 16:29:16
【问题描述】:
****EDIT** 每个人都说这样称呼它
FunctionTestTest.numberCheck(userNumber);
我已经尝试了很多次,然后在这里发布它没有工作。
人们对他们甚至无法回答的问题投了反对票,太好了...
在我正在处理的另一个项目中,我无法调用另一个类的函数。整天都在努力修复它。决定抛出几行代码并尝试从另一个类中调用一个函数,以确保我的主项目中没有未注意到的语法错误。
谁能看出这里有什么问题?
返回此错误:
cannot find the symbol
symbol: class FunctionTestTest
location: class FunctionTest
...
public class FunctionTest{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int userNumber = 0;
System.out.println("Please enter a number between 1 - 10");
userNumber = input.nextInt();
FunctionTestTest ft = new FunctionTestTest();
FunctionTestTest.numberCheck(userNumber);
}
}
和..
public class FunctionTestTest{
public static void main(String[] args){
}
public static void numberCheck(int num){
if (num == 1){
System.out.println("function works");
}
}
}
【问题讨论】:
-
你导入 FunctionTestTest 了吗?
-
您是否添加了
import声明? -
new FunctionTestTest(userNumber);-- 在这个类中没有这样的构造函数。事实上,这个类根本没有声明构造函数,只有一个(无用的)默认构造函数。 -
请注意,您是在询问对基础问题的误解,通过学习教程和书籍而不是在这里提问可以更好地解决问题。
-
非常同意充满鳗鱼的气垫船。似乎 OP 不知道如何将不同的类放在同一个包/项目文件夹中,从而导致所有混乱。
标签: java function class methods