Question:
Why can't i get Hello world to work (Java)?
Brendan
2012-06-30 19:30:08 UTC
I'm new to programming and i installed JDK and Eclipse (64 bit for windows). So the book i got told me to put in:

package beginning_java_7.examples.hello;

public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}

When I try and run it in eclipse, it says "Editor does not contain a main type," but it does though. Help is greatly appreciated
Four answers:
Jared
2012-06-30 19:57:38 UTC
Y!A doesn't respect spaces (it's really annoying, particularly for this section). I have since learned (thanks to someone else's post), to use this site for displaying code:



http://ideone.com/



So here is your code with proper indentation: http://ideone.com/B0nVB



Anyway, I suspect the problem is that you need to choose "Run As..." the first time you want to run a program (I don't remember always having to do this, but I have noticed it as of late).



So choose Run as..., then Java Application.
James Bond
2012-06-30 20:45:23 UTC
May be space after String

public class Hello {

public static void main(String [] args) {

System.out.println("Hello, World");

}

}



Just to work at barest level, i.e forgetting fancy IDEs

goto command or DOS prompt and then type

javac Hello.java

java Hello



Makesure Hello.java file is in the same directory where you are currently working
bilderback
2016-10-14 05:17:21 UTC
someplace on your undertaking you desire a substantial approach. the class that makes use of the main significant approach is the 1st to be accomplished. In a software so common as this you purely have one type and one substantial approach. the rationalization why you may not execute the 1st software is because of the fact the command instant is calling forward to to run a style with a substantial approach interior it. the 1st software is assuming that it's not the only type in the undertaking, while in certainty that's. it is likewise set as much as apply procedures from the class ConsoleProgram, which you in addition to mght in all probability do not desire. in the journey that your instructor/professor is coaching you the 1st approach i've got confidence very sorry for you and anticipate to work out you returned right here lots. the 2nd is the way which you relatively desire to pass.
green meklar
2012-07-01 16:52:15 UTC
Is the file you're typing this in called Hello.java? It is important that the name of the file matches the name of the outermost class declared within it.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...