Reputation: 13
I'm just starting to learn making GUIs and this is the first problem: when i try:
Toolkit tk = new Toolkit.getDefaultToolkit();
I get this error
Toolkit.getDefaultToolkit cannot be resolved to a type
I am on Mac Yosemite with Eclipse "Luna Service Release 1 (4.4.1)" what ever that is. if i run java -version on the terminal i get :
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
Upvotes: 1
Views: 3712
Reputation: 201507
You call Toolkit.getDefaultToolkit()
without new
like
Toolkit tk = Toolkit.getDefaultToolkit();
And, it doesn't hurt to make sure you have the import
import java.awt.Toolkit;
Upvotes: 3
Reputation: 458
if imports are missing in eclipse:
click on the Toolkit
class - then press ctrl+1 - now chosse the quickfix offered. That will import the class automatically
or: press ctrl+shift+o - choose the import you need
Upvotes: 0
Reputation: 311018
Remove the new
. You're not invoking a constructor, you're calling a factory method.
Upvotes: 0