eclipse - active editor does not contain a main type
Mahesh Trikannad
Ranch Hand
Joined: Dec 14, 2004
Posts: 66
posted
1
Can someone please help me with this error.
I try to run a Java program from Eclipse, using run -> run as -> java application and get "Active Editor does not contain main type"
Appreciate a quick reply
Mahesh
[Edited to remove caps from subject. All caps looks like shouting on the net.] [ December 18, 2004: Message edited by: Jeanne Boyarsky ]
Mahesh Trikannad
Tom Katz
Ranch Hand
Joined: Aug 19, 2002
Posts: 169
posted
0
I use Eclipse 3.0 and have never seen this particular error. Are you able to run the class from command line outside of eclipse?
Or maybe the file thats in focus (unintentionally) has no main function, and that's why it's complaining.
I usually find it helpful to set up the debug configurations for whatever code I need to run. I believe the 'main type' they're referring to is what you list as your 'Main class' in the debug configuration definition.
Yup - you must be trying to run a class as an application which has no main method (please Tom - functions belong in VB). Out of curiousity I just tried to run the interface I'm currently writing via Eclipse in the same way and thats the exact error I see.
ahhh, good point.. I tend to use both terms interchangeably...
Mahesh Trikannad
Ranch Hand
Joined: Dec 14, 2004
Posts: 66
posted
0
I did have a main in the class. I had ran it on UNIX>
It doesnt seem to select the right config while launching for some reason.
Iam new to Eclipse , so Iam still grappling with it.
If I right click on the file and say run , should it not pick the class by default. doesnt seem to do that. Rather I have to pick a config which specifies the file.
Paul McDonnell
Greenhorn
Joined: Jan 11, 2005
Posts: 3
posted
0
I'm looking for solutions to the same problem, and can't find very much at all. I've been using Eclipse 3.0.0 for several months with Java 1.4.2 and Jigloo 2.7.2. I've never had problems creating an SWT Main Application before, but attempts today have been failing with this "active editor does not contain a main type" message when I try to run a newly created application. Worth noting that existing apps in the same project run ok.
Scouring the internet did bring up a reference to a bug showing the same symptoms in Eclipse 2.1, but supposedly this is now fixed.
In desparation, I'm arranging to restore my project from a backup taken last night.
Has anyone got any more ideas?
Paul McDonnell
Greenhorn
Joined: Jan 11, 2005
Posts: 3
posted
0
Just an update... the restore of my workspace didn't solve the problem.
Paul McDonnell
Greenhorn
Joined: Jan 11, 2005
Posts: 3
posted
1
I'm extremely embarrassed to say that I've found the problem. I'd forgotten to put in the VM Arguments. Just in case it is of use to others, the details are as follows. Select run... , and then the VM Arguments tab and enter the appropriate path with -Djava.library.path=blahblahblah.
I have the problem "selection does not contain main type".
In the run-menu, I have
Run Debug Run History Run As Run Configuration Skip All Breakpoints Add Java Exception Breakpoint Add Class Load Breakpoint External Tools
I don�t find the VM - options. Of course you must have had an older version of Eclipce.
We were not born out of our free will.
shihab K Bava
Greenhorn
Joined: Oct 03, 2004
Posts: 12
posted
0
Dear friends,
When I tried to run the above vlas from eclipse I got an error "editor does not contain main type". But when copy the class to another package it works fine. Any clues?
THe main point is I am trying to run some demo applications. All libraries and jar files are there in my systesm and path and classpath variable are correct. But when I am tryign to run a class which have main,, it gives the same error. So that I created a test class (above class) and tried to run. When that class in the package demos.texture it gives error. But when the test class copied to another package it works fine. Any one can help?
Paul McDonnell wrote:I'm extremely embarrassed to say that I've found the problem. I'd forgotten to put in the VM Arguments. Just in case it is of use to others, the details are as follows. Select run... , and then the VM Arguments tab and enter the appropriate path with -Djava.library.path=blahblahblah.
I'm having the same problem on Eclipse 3.3.2, and, the main procedure exists. Sorry, I'm new to java, do you have more specific information on what you did to resolve this issue?
Jon
Wayne Bangerter
Greenhorn
Joined: Jun 21, 2009
Posts: 1
posted
0
I had this error and noticed my main class was not under the default directory. I tried to move the class under default and it disappeared. I then ran restore from local history and it showed up under src again, but not under default.
I created a new project and moved all the classes under its default directory. It is working there.
Rakshith Begane
Greenhorn
Joined: Jul 04, 2009
Posts: 2
posted
0
The problem is that class file is not automatically generated by eclipse.. since it is not there in .classpath file. To resolve it either edit .classpath file manually or add the source dir in you project build path, you can do it by right click on project, click on project properties, then a window appears. in left pane there is build path click on it and configure properly
Wayne Ban
Greenhorn
Joined: Jul 04, 2009
Posts: 2
posted
0
Why did it work when I moved it to a copy project?
Rakshith Begane
Greenhorn
Joined: Jul 04, 2009
Posts: 2
posted
0
i dont know the exact cause.. but eclipse adds dir in .classpath file when new directory or package is created..
Wayne Ban
Greenhorn
Joined: Jul 04, 2009
Posts: 2
posted
0
I know if I enable Maven dependency, that Eclipse will not be able to find the main method. Is it possible to take a class out of the classpath (java.build.path) if it is in the default directory?
Thillakan Saba
Ranch Hand
Joined: May 15, 2007
Posts: 53
posted
0
I had same problem, I have to add that file to build path. after adding that file to build path. It worked fine.
Go to package explorer --> build --> Add to build path || Include
Hey Incase this is still relevant, I believe I understand why you're having that problem, you don't have a
"public static void main(String[] args) " line in your coding.
My class instead used a constructor "public driver" instead of the above mains arguement;
"public class driver {
private DrawingGizmo pencil;
public driver() {"
I wrote a third programme to run my class, the name of the class is run, see below;
"public class run {
public static void main(String[] args) {
driver driver = new driver();
}
}"
So now I click on that class, then select run, and run as application ^ ^, took me over an hour to figure that out.
Hi Wilson
Welcome To Javaranch.
The problem is solved ages before
harshi Sum
Greenhorn
Joined: Jan 18, 2011
Posts: 5
posted
1
Just moving the java file to the src folder solved my problem.
Dave McQueen
Greenhorn
Joined: May 22, 2009
Posts: 29
posted
0
For this it sounds like your source isn't set up properly. If you look at the little icon for your class, do you see a "J" (for Java class) beside the class name as having a blue outline? If it's a "J" with a blue outline as opposed to a solid blue "J" (where it's all blue, not just the outline) then it means Eclipse isn't finding your source, even though it should!!
To fix this right click on your class, Choose Build Path -> Configure Build Path and choose the Source tab. Make sure that there is something in here as it tells Eclipse where to find your source (as I understand Eclipse) and that the folder points to your source file. Sometimes it just stays at <root package>/src even though it should change to where you've put your class e.g. <root package>/Implementation/Pages. You would therefore need to remove this <root package>/src folder and click 'Add folder' and choose <root package>/Implementation/Pages.
I don't know whether this is a Java necessity or an Eclipse one but it causes many problems!
Before you criticize someone, try walking a mile in their shoes. That way you'll be a mile away from them. And you'll also have their shoes.
Ajay Chowdary Kandula
Greenhorn
Joined: Aug 16, 2007
Posts: 12
posted
0
harshi Sum wrote:Just moving the java file to the src folder solved my problem.
Simple and Effective answer
Resolved my error too but lacked in explaining what caused the error and why is it so