Reputation: 1
I'm running Java program in Eclipse and I'm calling one class from another class. if I run the class that contains the main
method it gives an error like:
could not find main class. program wil exit
A sample code is:
public static void main(String[] args)
{
Test t1=suitToRun();
TestRunner.run(t1);
}
public static Test suitToRun()
{
TestSuite suite= new TestSuite();
suite.addTestSuite(Login.class);
return suite;
}
Upvotes: 0
Views: 6104
Reputation: 11
Go to Run -> Run Configurations..
Make sure u have written name of Main class and Project in their respective places on right side of box..Main class option just requires name of the class containing main function and project option requires name of ur project..(take care of lower n upper cases).. ;)
Now..
If at the top of box if u can see the error
" [JRE]: JRE not compatible with project .class file compatibility: 1.7 "
then u r lucky as it can be rectified.. it is thr becoz ur Compiler Compliance level is set to the version of JAVA which is not there in ur computer or not included in Eclipse..in this case '1.7' so u just need to set it to low level (1.6, if it is already set to 1.7)..to do that,just follow d followin path..
Project-> Properties
Click on Java compiler option in the left column n set ur desired Compiliance level shown on the right side then press ok and yes to the pop up and run it from the toolbar with ur fingers crossed...
hope it helps :)
Upvotes: 0
Reputation: 46147
This usually happens when your JAVA file has not been successfully compiled (to the .CLASS). Common fixes to this is to CLEAN (Menu > Project > Clean...) your project or rectify your JRE setting in Eclipse (or your Project, if its project specific).
You can quickly check this by right-clicking on the Java file, Run As > Run Configurations.... If you have an error, you should see an error in the dialog box that pops-up (right at the top).
Upvotes: 2