Log in

View Full Version : Just installed Java: example won't compile


de_
10-08-2011, 19:21
Been following the "Getting Started With Java for FRC Doc"
Believe I have installed everything as per pages 1-5
Created robot project as per page 7 (SimpleRobotTemplateProject) but it fails to compile with following error
"<identifier> expected public class 1310Robot extends SimpleRobot"

Noted "import edu.wpi.first.wpilibj.SimpleRobot;" line has an information yellow light bulb saying "Unused Import"

Also if I comment out" package edu.wpi.first.wpilibj.templates;" there is no change in behaviour.

Been stuck a while. Any suggestions ?

Sunstroke
14-08-2011, 21:55
So you should definitely keep the package line where it was.

You should also have the top of the class be (after the package declaration and the import stuff):

public class 1310Robot extends SimpleRobot {
...
}

My guess is that you removed the "extends SimpleRobot" part, which would cause the "Unused Import" warning.

de_
24-11-2011, 20:48
(appears to be) Resolved

Changed the name of the class from 1310Robot to T1310Robot (as well as file name and project name) and now it compiles. From this I can only conclude Java must not allow class names starting with numerics and the compiler does not have an error message that reflects that. The error message it put out was highly misleading. Ouch.

linuxboy
25-11-2011, 00:08
(appears to be) Resolved

Changed the name of the class from 1310Robot to T1310Robot (as well as file name and project name) and now it compiles. From this I can only conclude Java must not allow class names starting with numerics and the compiler does not have an error message that reflects that. The error message it put out was highly misleading. Ouch.

Yup, thats correct. And the error message is technically meaningful since 1310Robot isn't a valid identifier, its just not specific as to why.

The rules for java naming are:
Start with a letter, underscore, or dollar sign
After that, anything but spaces and special chars
Case sensitive
Can't use a keyword (like class or public)
(Paraphrased from http://mathbits.com/mathbits/java/DataBasics/Namingrules.htm)

Oliver

de_
25-11-2011, 13:21
Thanks for the info.

I hate to say having been in programming in just about every language that exists for the past 30 years (except Java), I was hoping compiler messages might have improved over the years and become a little less terse and a little more user useful. Something like "I don't know what "1310Robot" is, it does not start with a letter, $ or underscore" would have saved me many hours of (unpaid voluteer) time that I can not get back (nor my project schedule)@#$%

Looks like I can't count on learning Java rules via the compiler error messages so thanks for the link and I will look around for a good (concise) reference source :)