aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes eclipse - active editor does not contain a main type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "eclipse - active editor does not contain a main type" Watch "eclipse - active editor does not contain a main type" New topic
Author

eclipse - active editor does not contain a main type

Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
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
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
ahhh, good point.. I tend to use both terms interchangeably...
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
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
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
Just an update... the restore of my workspace didn't solve the problem.
Paul McDonnell
Greenhorn

Joined: Jan 11, 2005
Posts: 3
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.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Paul,
Thanks for sharing the answer!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Valter Hall
Greenhorn

Joined: Nov 14, 2008
Posts: 2
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


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?

Thanks and Regards
Shihab
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Edit: answer moved to your own topic: http://www.coderanch.com/t/431735/IDEs-Version-Control-other-tools/eclipse-editor-does-not-contain

Please do not resurrect old topics. Start a new topic for each independent problem and please stick to it.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

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
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
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
Why did it work when I moved it to a copy project?
Rakshith Begane
Greenhorn

Joined: Jul 04, 2009
Posts: 2
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
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
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


HTH

SCBCD, SCJP & MCP
HowToAskQuestions
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

hi,

I am also facing the same problem......
i also added the file to my build path........but that doesnot even works for me.

Is there any solution.......

SCJP6.0,My blog Ranchers from Delhi
Wilson Ford
Greenhorn

Joined: Sep 27, 2010
Posts: 1
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.

Ciao ^ ^

Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Hi Wilson
Welcome To Javaranch.
The problem is solved ages before
harshi Sum
Greenhorn

Joined: Jan 18, 2011
Posts: 5
Just moving the java file to the src folder solved my problem.
Dave McQueen
Greenhorn

Joined: May 22, 2009
Posts: 29
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
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

Thanks ;) you rock!!!


Is it Work-Life Balance or Life-Work Balance ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: eclipse - active editor does not contain a main type