I am unable to run the following code in Eclipse (Eclipse IDE for Java Developers, Version: Indigo Service Release 1, Build id: 20110916-0149), and I think that I may have a configuration problem in Eclipse (but I do not know what or where):
class Saluton {
public static void main(String args[])
{
String greeting = "Saluton mondo!";
System.out.println(greeting);
}
}
I am also running against Java 6 (1.6.0_29-b11-402) on Macintosh 10.7.2.
When I run this, I get the error:
"java selection does not contain a main type"
but I am pretty sure that my class is written correctly...? I have looked this error up, and cannot explain this problem so far.
TIA for any thoughts or opinions!
I think you have to make your class public, otherwise it won't work?
EDIT: My previous answer was incorrect. The JLS says you can declare arrays with the brackets at either end. See here for some examples. My mistake.
Have you verified your configuration in Eclipse such that it knows where to find the Java compiler, and a JVM? You can check the project-specific libraries by right clicking the project and going to Properties, Java Build Path
You can also check the JRE's installed by clicking Window, Preferences, Java, Installed JREs. Make sure the JRE you wish to use is listed here and that the path is correct.
Another solution (simple and direct):
In Eclipse: File -> Restart
Right click your class Saluton
and choose Run as --> Java Application.
It should work.
Ok, so I'm a fellow noob, and I came here because I had this problem. I checked all my class paths and everything, and they were correct. I had actually been putting all of my files in the JRE System Library Folder, instead of the source folder. I'm not sure if this was you'r problem, but it seemed to work for me when I moved the code files into the src folder.
I took the long way around to solve this; eventually I created a package within my project and added my source code to that package and it compiled and ran! I am learning that Wizards rule!
It will work if you make your class as public !