Hello everyone,

I have a book called "Java Genesis" and it has some files such as packages, projects and hints to enhance learning. So, I have set up a file structure in Eclipse and it shows that there are errors and warnings. When I tried running a Java Application using these files, a major message came up "Editor does not contain a main type". I went through the code and there was

public static void main (String [] args) {

Your help is greatly appreciated and Thanks in advance.

Recommended Answers

All 23 Replies

Well, if Eclipse "shows that there are errors and warnings" then that class is probably not being compiled and so the project does not contain an executable main class. Fix the "errors and warnings", first.

Click the Src package u have made, i think you must clicked some library and running the application....

I clicked on SRC then imported the packages I wanted to run with their accompanying files that support them.


@ Masijade, These packages and projects are from a book. Therefore, they are not written for readers to complete them; they're meant to help readers understand how an app works and play around with the code.

it will be very easy for us if u take two or three snapshot of your screen and load here.............

@ Masijade, These packages and projects are from a book. Therefore, they are not written for readers to complete them; they're meant to help readers understand how an app works and play around with the code.

Okay? And? How does that change anything I said? If it doesn't compile it is not a main class. It is an attempt at a main class, but until it compiles there is nothing for Eclipse to execute.

It is strange that eclipse doesn't find any code to execute. How do you think I can possibly fix the issue?

Please post pictures..... I already told u , no body guess what the problem is.

well .. just posting

public static void main(String[] args){

says nothing. for all we know, this main method is declared within another method.
so, show the error message (stacktrace, ...) you get, and post some code in which we can see something.

It is strange that eclipse doesn't find any code to execute. How do you think I can possibly fix the issue?

You said that Eclipse "shows errors". Well, how do you propose that Eclipse execute anything that isn't compiled? This is not a scripting language, you know. As I said, fix those errors.

Are u sure ur java file is in src folder ??

they are supposed to be in the src folder ,but when I imported the files, the child files got into their parent folder (well, they were in their parent folder)if this makes sense.

I remember having a similar problem, it was saying couldn't find the main, but it was there... I think I solved it just by refreshing the src folder in eclipse, not sure anyway. And I don't know why it said that in the first place

These are the print-screen images as requested before and hopefully are illustrating well to you guys. Looking forward to getting a solution to this problem from you all. Thanks in advance.


cheers,

You have 689 uncorrected compile-time errors. Yet you say

It is strange that eclipse doesn't find any code to execute. How do you think I can possibly fix the issue?

There won't be any code to execute until the compiler generates some. The compiler won't compile your code until you fix the errors. Start with the first error and keep fixing them until they are all fixed. Then you will get some code to execute.

ps: Such a large number of errors suggests that you have problems with your project setup, eg incorrect path(s) - but the detailed messages will spell it out for you.

Bear in mind that I'm still new to Java language..

Bear in mind that I'm still new to Java language..

That may be so, but Java and Eclipse work the same way regardless of your experience

I've already told you that until it compiles there is nothing to execute.

And, as far as being new goes, then you need to start with something simpler, such as the official tutorials.

commented: hear yeh, hear yeh .. +10

This is not helping at all, guys. I don't want to change anything written in those classes because they seem to be built on the top of each other.

I never ever down-voted on all forums where I member of, you are 1st. candidate during this month, are you thinking about that all posters in this thread just wasted her/his time for your ...., everything is wrong

There are alot error. If you want to make them run then try to solve each error, eclipse is one of the best Java visual editor tool, simply bring cursor over the error and it will provide you help that how to resolve that error. U can post more problem after that , finally every thing will start working. :)

This is not helping at all, guys. I don't want to change anything written in those classes because they seem to be built on the top of each other.

What would you like us to do to help you? Please believe that we cannot change the way that Java works. You have a project with over 800 errors. There's nothing that anybody on Earth can do to make that work without fixing the errors.
If you have any religious beliefs then maybe praying will work for you.
Good luck.
J

From the screenshot, I assume that you took all the files form somewhere else and put them in eclipse? If that is the case, then I see that you took the .java files and the .class files and put them in same folder src/
I think, without knowing your settings, that since the .class files are in the src/ folder it doesn't find them because you haven't set the classpath to see them.
Even if changing the classpath to look at the src folder might make you project compile it is not the right way. The .class files should be put in a different folder

Also if you have code that works but what you have written that uses that, doesn't compile is probebly because you haven't set the classpath to "see" it.
Go to the Project properties and look at the java build path or search for tutorials about how to set the classpath with eclipse.

I solved the problem by just declaring a package name which was undeclared before and Eclipse did not complain about it.


Thanks all,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.