-2

i'm using NB.the ide gives error that it cannot find symbol java.awt . tried running the same code in eclipse.it also gives same error. it gives the error cannot find symbol even on creation of new JFrame.

An error:

enter image description here

DimaSan
  • 10,315
  • 10
  • 56
  • 68
shardul
  • 3
  • 4

1 Answers1

1

A class named java obscures the package name java, see Java Language Specification 6.4.2:

A simple name may occur in contexts where it may potentially be interpreted as the name of a variable, a type, or a package. In these situations, the rules of §6.5 specify that a variable will be chosen in preference to a type, and that a type will be chosen in preference to a package. Thus, it is may sometimes be impossible to refer to a visible type or package declaration via its simple name. We say that such a declaration is obscured.

That means that within the package that contains the class java you will not be able to reference to classes from any of the java.* packages through qualified names.

However you could still import the classes you need and reference them by simple names:

import java.util.logging.Logger;
import java.awt.EventQueue;

// within some method:
    Logger.getLogger(....);
Thomas Kläger
  • 10,196
  • 2
  • 16
  • 27