It's driving me crazy, 24 errors produced when I run this simple Java program. -


public class planet {     double x;     double y;     double xv;     double yv;     double mass;     double imgname;     public planet (double x; double y; double xv; double y; double mass; double imgname;) {         this.x = x;         this.y = y;         this.xv = xv;         this.yv = yv;         this.mass = mass;         this.imgname = imgname;     }     public static void main(string[] args) {         return 0;     } } 

planet.java:8: ')' expected

planet.java:8: illegal start of type

planet.java:8: ';' expected

planet.java:9: illegal start of type

planet.java:9: expected

planet.java:9: ';' expected

planet.java:9: illegal start of type

...

planet.java:16: class, interface, or enum expected public static void main(string[] args)

planet.java:18: class, interface, or enum expected }

i see different types of error! explain them 1 one me annoying.

you not declaring parameters properly. use:

public planet (double x, double y, double xv, double y, double mass, double imgname) 

additionally, main should not return 0. if want return system exit code, use system.exit(0). returning main method (using return; or reaching end of it) act analogously return 0; main languages c.

the reason there many errors due way java parser/compiler works. first error incorrect state, following errors artifacts of compiler being "confused".

a practical rule of thumb compile/syntax errors focus on fixing first error given, parsing of rest of file affected it.

although not 100% believe following occuring:

  1. semicolon causes parser emit error of missing closing ), , end statement (in fact, ending constructor , there).
  2. after last semicolon, ) illegal type, , semicolon additionally expected.
  3. although human conclude this.x = x part of constructor, previous line confused parser thinks it's working @ class scope (not in method). can't parse this.x = x because this.x isn't valid type, , "field" doesn't have name. @ point, clear previous errors have messed parser state enough begin panicking valid statements believes out of place.
  4. as reaches closing } ends class scope. following main method , final closing } likewise unparseable, , cause errors emitted (since these elements not inside class @ point)

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -