Reputation: 10204
Below my Test.java which is one .java file from a student project. I don't see why eclipse gives me " Selection does not contain any Java files " error when I tried to "run" it from the menu Run-->Run ? Could you explain why?
This post Java launch error selection does not contain a main type does not explain my problem. In my case "main" is well defined.
class Test {
public static void main(String[] args) {
test1();
}
static void test1() {
Font f = new Font("SansSerif", Font.PLAIN, 70);
Glyph g = new Glyph(f, 'g');
System.out.println(g);
}
}
Upvotes: 2
Views: 2052
Reputation: 328614
The problem is that the file isn't in a source folder. So for Eclipse, it's just a text file which (by coincidence) contains some Java code. But since the compiler never saw it, there is no .class file -> Eclipse can't run it.
Create a source folder (New... -> Source Folder) or move the file into an existing source folder in your project (they contain a little "package" symbol in the icon) and try again.
Upvotes: 3
Reputation: 83
Haven't used eclipse in some time now as I use InteliJ but make sure you edit configurations and select your main file so Run can then execute your app.
Upvotes: 0
Reputation: 15109
The name of the file and the name of the class should match. That is the reason, it's not able to recognize it. Please check the name again.
Upvotes: 1