I created a class/program in Eclipse with no errors. When I go to run it I select "run as" and I only get the option "run configurations" I don't get the option "Java Application".
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I created a class/program in Eclipse with no errors. When I go to run it I select "run as" and I only get the option "run configurations" I don't get the option "Java Application".
Last edited by Norm; August 31st, 2013 at 07:12 PM. Reason: Moved to IDE section
Does the class have a main() method? If yes, then post the code so that we can see what's wrong with it.
In the Eclipse where u have written the class.
package com.java.src; class Point3D { double x; double y; double z; Point3D(double ax) { x = ax; y = 1; z = 1; } Point3D(double ax, double ay) { x = ax; y = ay; z = 1; } Point3D(double ax, double ay, double az) { x = ax; y = ay; z = az; } class Point3DOverloadConstructors { public void main(String args[]) { // TODO Auto-generated method stub Point3D p1 = new Point3D(1.1); System.out.println("p1.x = " + p1.x); System.out.println("p1.y = " + p1.y); System.out.println("p1.z = " + p1.z); Point3D p2 = new Point3D(1.1, 3.4); System.out.println("p2.x = " + p2.x); System.out.println("p2.y = " + p2.y); System.out.println("p2.z = " + p2.z); Point3D p3 = new Point3D(1.1, 3.4, -2.8); System.out.println("p3.x = " + p3.x); System.out.println("p3.y = " + p3.y); System.out.println("p3.z = " + p3.z); } } }
Last edited by jps; September 1st, 2013 at 02:36 PM. Reason: code tags
The main() method must be declared static, and it must also be in the top-level public class.
Your class Point3DOverloadConstructors is currently enclosed in Point3D because (I think) you missed adding a close brace, '}', before the declaration of class Point3DOverloadConstructors. Fix those errors and make sure the open and close braces match up, and all should be well - at least with the Eclipse problem you've described. I didn't check to see that the program does as it should beyond that, because you didn't ask.
It was static but I get a error message that says "a static method can only be declared in a static or top level type"
In the code you posted, it WAS not static, so you must mean that you added the static keyword.
And, yes, I already explained to you that the class with the main() must be the top-level public class and that you had a close brace out of place or just plain didn't put one where it is supposed to be. This is the correct structure and formatting of the code you've posted. I also made the main() method static, but that's the only other code change I made, even though I want to fix your odd (mis)use of whitespace.
package com.java.src; class Point3DOverloadConstructors { public static void main(String args[]) { // TODO Auto-generated method stub Point3D p1 = new Point3D(1.1); System.out.println("p1.x = " + p1.x); System.out.println("p1.y = " + p1.y); System.out.println("p1.z = " + p1.z); Point3D p2 = new Point3D(1.1, 3.4); System.out.println("p2.x = " + p2.x); System.out.println("p2.y = " + p2.y); System.out.println("p2.z = " + p2.z); Point3D p3 = new Point3D(1.1, 3.4, -2.8); System.out.println("p3.x = " + p3.x); System.out.println("p3.y = " + p3.y); System.out.println("p3.z = " + p3.z); } } class Point3D { double x; double y; double z; Point3D(double ax) { x = ax; y = 1; z = 1; } Point3D(double ax, double ay) { x = ax; y = ay; z = 1; } Point3D(double ax, double ay, double az) { x = ax; y = ay; z = az; } }
What do you mean by "odd (mis)use of whitespace"? Forgive me if this is a simplistic question, I am a old (30+ years) cobol programmer trying to learn a new language.
It's more of a curiosity than anything else. The vertical spacing and resultant 'pacing' in your source code appears to be inconsistent and arbitrary. I see it often, and I always wonder why it's there.
Since it is common in source code from new programmers, it's not odd in that sense. It is odd in the sense that 1) new programmers can never explain why it's there (they don't know it matters or that anyone else would even notice or care), 2) the existence of unnecessary and inconsistent whitespace doesn't 'bother' them, and 3) the inconsistent use of unnecessary whitespace is uneconomical and unstructured, contrary to the typical habits of a programmer.
So, not a big deal, but a curiosity, and it pained me (a little) to re-post your code with the vertical spacing preserved.