Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Launch Error in Java(Selection does not contain a main type)
Launch Error in Java [message #1695985] Wed, 20 May 2015 16:50 Go to next message
Eclipse UserFriend
Greetings,
I am new to Java programming.
I managed to run simple one or two java files from scratch. However when I try to run java files already developed from textbook (downloaded), I am running into problems. Those files were written with references to other files which means that they have their own folder names etc in package and import reference. It is troublesome when I have 10's of files to modify. Therefore I created folders referred by those java files. It is correct because I am not getting debug - error flags on number column in editor. However when I try to compile the file I am getting 'selection does not contain a main type'. Therefore, I decided to give a build path which means that compiler will not need to go to source folder. On the file tree you will notice that those files will move to default folder from project folder. When it happens, I am getting a lot of error flags on original java file which leads me to believe that package command and import command cannot find the reference folders. The problem is that if I correct this file import reference which is easy I will have to correct many other java files being referred because they have the same folder tree structure. Is there a way to avoid this and make it compile without modifying the code? Please see pdf of 3 pictures for clarification and look at the files tree on the left column. Thanks.
Note: No error flags when code.java is in project folder but will not compile
Lots of error flags when code.java is in project/source/default folder.
Problem: lots of code.java have package and import refer to folders
  • Attachment: error.pdf
    (Size: 514.90KB, Downloaded 539 times)
Re: Launch Error in Java [message #1696201 is a reply to message #1695985] Fri, 22 May 2015 19:39 Go to previous message
Eclipse UserFriend
Hey Adam, no, both things you tried are wrong. Sorry. Sad

When you created your "ch02" project, you should have had folder called "src" and the "JRE System Library" (it's kind of a fake folder, don't worry about it). Your source code goes in the src folder. But, and this is crucial, you first need to create packages inside the src folder that match the structure of the "package" statement in each .java file, then put each .java file in the right package. So, for CalculationApp, your structure should look like this:

ch02
-> src
---> org
-----> opensourcephysics
-------> sip
---------> ch02
-----------> CalculationApp.java
-----------> SomeOtherJavaFile.java
-----------> YetAnotherJavaFile.java


BTW, your code is automatically compiling already. Those "error flags" in the first page of your pdf? Those are compile errors. I think maybe the other two screens have no errors because Eclipse couldn't recognize that you intended those files to be compiled (because they aren't inside a source folder like "src" (although maybe your classpath stuff overcame that somehow)), and consequently couldn't find the "main" method in CalculationApp when you tried to run ("launch") it.
Previous Topic:How to install WebTools on Kepler?
Next Topic:Relaxing annotation based null checks on JDK8
Goto Forum:
  


Current Time: Tue Apr 29 08:31:20 EDT 2025

Powered by FUDForum. Page generated in 0.29306 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top