W
William Colls
I am novice with Eclipse, and a beginner with Java, but I have 20+ years
experience as a programmer - coming to OO late in life.
I Have some code that looks like this:
// begin java
package com.mine.package
class MyClass {
import java.io.*
public static void main() {
try {
runMyMethod(); // <---- error here
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void runMyMethod() throws Exception {
// do some things
}
}
// end java
However, Eclipse generates the error "Cannot make static reference to to
non-static method in type MyClass" at the point noted.
I understand what it means (I think), but I don't understand why it is a
problem, and more importantly - How to fix it. There is a whole bunch
more stuff in the class. Making runMyMethod static fixes the problem
here, but then everything else in the class also has to be static.
Eventually, the class MyClass will be integrated into a much larger
project, and the local main method goes away. I tried creating a
seperate class with the main method, and importing MyClass. However,
Eclipse seemed to be unable to resolve the runMyMethod from the imported
class. But maybe I wasn't doing it properly.
If anyone can offer guidance and/or suggestions as how best to proceed,
I will be most greatful.
Thanks all for your time.
William.
experience as a programmer - coming to OO late in life.
I Have some code that looks like this:
// begin java
package com.mine.package
class MyClass {
import java.io.*
public static void main() {
try {
runMyMethod(); // <---- error here
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void runMyMethod() throws Exception {
// do some things
}
}
// end java
However, Eclipse generates the error "Cannot make static reference to to
non-static method in type MyClass" at the point noted.
I understand what it means (I think), but I don't understand why it is a
problem, and more importantly - How to fix it. There is a whole bunch
more stuff in the class. Making runMyMethod static fixes the problem
here, but then everything else in the class also has to be static.
Eventually, the class MyClass will be integrated into a much larger
project, and the local main method goes away. I tried creating a
seperate class with the main method, and importing MyClass. However,
Eclipse seemed to be unable to resolve the runMyMethod from the imported
class. But maybe I wasn't doing it properly.
If anyone can offer guidance and/or suggestions as how best to proceed,
I will be most greatful.
Thanks all for your time.
William.