开发者

Eclipse fails to compile pasted code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 3 years ago.

Improve this question

This may be a stupid mist开发者_运维技巧ake of some sort on my part, but I'm walking through a Java GUI tutorial. When I copy and paste code from the tutorial into Eclipse, it finds an error in the pasted code. Trying to run it anyways yields console errors and an empty GUI window.

For example:

Checkbox chk15to20 = new Checkbox(“15 to 19 years old”, true, age);

Eclipse yields an error on the argument string, saying "Syntax Errors, ArgumentList expected instead" and "years cannot be resolved to a type."

I can fix the problem by manually re-typing, character by character, the code, at which point it compiles correctly.

Here's the error log when it's run (class is called Buttons):

java.lang.Error: Unresolved compilation problems: Syntax error on tokens, ArgumentList expected instead years cannot be resolved to a type Duplicate field Buttons.old Syntax error on tokens, ArgumentList expected instead Duplicate field Buttons.old

at practice1.Buttons.<init>(Buttons.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


Your double-quotes are wrong. You need to use normal double-quotes, i.e. press SHIFT and ' on a US keyboard.

Like this:

Checkbox chk15to20 = new Checkbox("15 to 19 years old", true, age);


It looks like you have stylized quotation marks in the first argument. Try replacing them by hand.

Checkbox chk15to20 = new Checkbox("15 to 19 years old", true, age);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜