小弟是初接触到java语言,也是自学java所以不断遇到新问题,
现在对类的调用问题很困惑,在网上找了半天,没找到一个好方法解决这个问题:
问题是这样的:
现在有两个类Exercise(它对应的文件名是Exercise.java)和Methods (它对应的文件名是GoodMethods.java);
两个类的源代码如下:
public class Exercise{
private void print() {
final Methods in = new Methods();
in.test();
}
public static void main ( final String args[]){
final Exercise object = new Exercise ();
object.print();
}
} public class GooodMethods {
public void test (){
System.out.println( "Hello,World!");
}
}
我想将GoodMethods这个类做为自己的常用类被其它类调用(这里为了简单只做个简单测试);
如,现在我想在Exercise类中调用GoodMethods类中test方法,用上面代码实现总报错:
我用Eclipse编译的,报错如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Methods cannot be resolved to a type
Methods cannot be resolved to a type at Exercise.print(Exercise.java:17)
at Exercise.main(Exercise.java:22)
ps:怎样解决这个问题呢?是不是像GoodMethods这样被调用类的书写格式有什么特殊的要求?
希望得到好心人的帮助?小弟不胜感激!
现在对类的调用问题很困惑,在网上找了半天,没找到一个好方法解决这个问题:
问题是这样的:
现在有两个类Exercise(它对应的文件名是Exercise.java)和Methods (它对应的文件名是GoodMethods.java);
两个类的源代码如下:
public class Exercise{
private void print() {
final Methods in = new Methods();
in.test();
}
public static void main ( final String args[]){
final Exercise object = new Exercise ();
object.print();
}
} public class GooodMethods {
public void test (){
System.out.println( "Hello,World!");
}
}
我想将GoodMethods这个类做为自己的常用类被其它类调用(这里为了简单只做个简单测试);
如,现在我想在Exercise类中调用GoodMethods类中test方法,用上面代码实现总报错:
我用Eclipse编译的,报错如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Methods cannot be resolved to a type
Methods cannot be resolved to a type at Exercise.print(Exercise.java:17)
at Exercise.main(Exercise.java:22)
ps:怎样解决这个问题呢?是不是像GoodMethods这样被调用类的书写格式有什么特殊的要求?
希望得到好心人的帮助?小弟不胜感激!
public class Exercise{ private void print() {
final GoodMethods in = new GoodMethods();
in.test();
}
public static void main ( final String args[]){
final Exercise object = new Exercise ();
object.print();
}
}
public class GooodMethods { public void test (){
System.out.println( "Hello,World!");
}
}
你这是 GoodMethods
public class GooodMethods
仔细对比一下吧。
现在有两个类Exercise(它对应的文件名是Exercise.java)和GoodMethods (它对应的文件名是GoodMethods.java
两个java要放在同一个目录下。编译的时候不要带参数。
但是我把GoodMethods的类名和文件名改成不同的情况下编译直接运行才报此异常。
你不妨再检查一下。
另外你的GoodMethods似乎多了一个O呵