Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Launch error(Java)
Launch error [message #1818721] Tue, 24 December 2019 14:26 Go to next message
Martynas Vertelis is currently offline Martynas VertelisFriend
Messages: 3
Registered: December 2019
Junior Member
Hello people, i am starting to learn Java (my first time learning programming language constructively, got just minor experience from many years ago) with use of Core Java Vol I. I have just installed Eclipse and after looking around the regular Welcome program wanted to play around a little to understand things better.
I have created new Java project all fresh with basic println but there seems to be an issue of sorts with my Eclipse. When i try to launch the FirstSample.java i get error as in the picture stating "Selection does not contain a main type". Tried to compile and launch it in terminal - all went just fine, so it doesn't seem like i wrote anything wrong inside the file.


When i copied the FirstSample.java to Welcome folder (just to see whats up, as Welcome is working) - it launched no problem. So it seems i am missing some steps in creating a new project? I set only the name of the project and left everything at default settings.

Can anyone point me the right direction, what am i doing wrong here?
  • Attachment: 111.png
    (Size: 81.21KB, Downloaded 730 times)
Re: Launch error [message #1818723 is a reply to message #1818721] Tue, 24 December 2019 14:48 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

You source file should be inside the "src" folder, and preferably in a package other than the default (when no package is declared). Otherwise the compiler doesn't know how to resolve anything your class refers to and anything that tries to refer to your class later on.

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Launch error [message #1818735 is a reply to message #1818723] Wed, 25 December 2019 12:56 Go to previous messageGo to next message
Martynas Vertelis is currently offline Martynas VertelisFriend
Messages: 3
Registered: December 2019
Junior Member
Thank you for your time answering this. I will give it a go.

And as we are on the topic, if its not too much to ask, could you tell me what/why is happening here:

As all i did here was on myself, rather than book asking me to go and make new project, etc. - so i decided to go step by step and try to do Hello World through eclipse walkthrough, which actually seem to have put me on correct path - before i was just creating a project but not a class afterwards and it would seem this was one of the issues. HelloWorld.java i placed in src folder as you mentioned before but ran out into different situation which i got resolved but do not really understand what was happening there.

I was receiving error "Must declare a named package because this compilation unit is associated to the named module 'HelloWorld'" on the first line, which was resolved by deleting module-info.java (which was added there automatically by Eclipse).

The question i have is why or maybe what is wrong with module-info being in the same folder and what is it supposed to do at all given its added automatically? And if it is relevant for future how can i declare a named package?

[Updated on: Wed, 25 December 2019 12:56]

Report message to a moderator

Re: Launch error [message #1818745 is a reply to message #1818735] Thu, 26 December 2019 17:14 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

module-info.java indicates you want to use the Java Platform Module System, which changes almost everything about how you compose and package your application. If that's wasn't your intention, never have that file.

When you create your project, take special note of the JRE option in the wizard. Anything higher than 1.8 will cause the option to create a module-info.java file to both be possible and selected. I'd suggest you specifically target the 1.8 Execution Environment to avoid this.


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Launch error [message #1818764 is a reply to message #1818745] Fri, 27 December 2019 16:57 Go to previous message
Martynas Vertelis is currently offline Martynas VertelisFriend
Messages: 3
Registered: December 2019
Junior Member
I see, that makes sense. I guess ill leave more in depth learning of this for appropriate time in my studies.

I have looked into this JRE version as you mentioned, and it does indeed not create module file. Did a lookup on this and from what i can find about it - older versions apparently are provided to help developers debug issues in older systems. Are there any pros or cons in regard to using older version, or in the end of the day it will not make much difference to me?
Previous Topic: Change language
Next Topic:Eclipse Installation issues.
Goto Forum:
  


Current Time: Fri Apr 19 06:32:08 GMT 2024

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

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

Back to the top