0

Is there any shortcut in Eclipse to import all required classes? A combination of keys?

For example I used the keyword Command and I'm not sure what to import because it doesn't recognize Command as type. I also have this error: The method printf(String, Object[]) in the type Console is not applicable for the arguments (String, int).

I think it needs me to import some packages that incorporate some of the methods that I am using which aren't in the default package. Any help appreciated. Thanks! Sam

Morten Kristensen
  • 7,412
  • 4
  • 32
  • 52
Sam
  • 3,067
  • 19
  • 53
  • 55
  • possible duplicate of [Eclipse ide quick fix all](http://stackoverflow.com/questions/6761639/eclipse-ide-quick-fix-all) – assylias Aug 24 '12 at 17:02
  • 1
    It will only suggest classes on the current project's classpath. If there isn't a `Command` on the classpath, it won't know what to import. If there are multiple `Command`s on the classpath, it will ask you. If *you* don't know which to import, Eclipse can't help you. – Dave Newton Aug 24 '12 at 17:04
  • Thanls assylias! However if I do CTRL+SHIFT+O I get this: "Compilation unit has parse errors. Syntax error, annotations are only available if source level is 5.0. No changes applied." – Sam Aug 24 '12 at 17:04
  • @Sam If I had to take a guess, that means you've got an error else-where – Alex Coleman Aug 24 '12 at 17:05
  • 2
    @Sam Then you *also* need to set up your project for the JDK version you actually want to use. – Dave Newton Aug 24 '12 at 17:05
  • @Sam You seem to be using annotations (like `@Override`) and your compiler is setup to an older version that does not support them – assylias Aug 24 '12 at 17:05
  • Ctrl-3, type `compiler - java`, select the only option. There set the source level appropriately. Also check Project Properties, Java Compiler (you could have Project-specific setting for source level). – Marko Topolnik Aug 24 '12 at 17:18

1 Answers1

0

You need to make sure Eclipse uses a source level of at least Java 5, otherwise var-args aren't implemented.

obataku
  • 29,212
  • 3
  • 44
  • 57
  • Hello, veer. Thank you. So by just downloading and installing an update from oracle.com, this would be fixed? http://www.oracle.com/technetwork/java/archive-139210.html: I found this - Java SE 7 downloads. – Sam Aug 24 '12 at 18:13
  • @Sam you should have a newer JDK already. You want to change the __Compiler Compliance Level__ setting. – obataku Aug 24 '12 at 20:57