This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

eclipse - active editor does not contain a main type

 
Ranch Hand
Posts: 73
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahhh, good point.. I tend to use both terms interchangeably...
 
Mahesh Trikannad
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just an update... the restore of my workspace didn't solve the problem.
 
Paul McDonnell
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
Thanks for sharing the answer!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edit: answer moved to your own topic: https://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.
 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why did it work when I moved it to a copy project?
 
Rakshith Begane
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont know the exact cause.. but eclipse adds dir in .classpath file when new directory or package is created..
 
Wayne Ban
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.......
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Wilson
Welcome To Javaranch.
The problem is solved ages before
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just moving the java file to the src folder solved my problem.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!!!
 
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic