MoDi
MoDi

Reputation: 13

Toolkit.getDefaultToolkit cannot be resolved to a type

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

Answers (3)

Elliott Frisch
Elliott Frisch

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

matthiasboesinger
matthiasboesinger

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

user207421
user207421

Reputation: 311018

Remove the new. You're not invoking a constructor, you're calling a factory method.

Upvotes: 0

Related Questions