2016-09-28 17 views
-2

我正在使用NB.the ide給出的錯誤是它找不到符號java.awt。嘗試在eclipse.it中運行相同的代碼也會產生相同的錯誤。它甚至在創建新的JFrame時都會給出錯誤找不到符號。找不到符號java.awt和java.util

錯誤:

enter image description here

+0

嘗試設置JDK項目。此鏈接幫助:http://stackoverflow.com/questions/4128256/change-jre-in-netbeans-project –

+0

@AlexChermenin我已經嘗試了上述解決方案,但它仍然給出了相同的錯誤 – shardul

+1

你有沒有機會有一個類或稱爲'java'的字段? –

回答

0

名爲java類掩蓋了包名java,看到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.

這意味着,包含類的包內0​​你不會能夠通過限定名稱引用任何java.*包中的類。

但是你仍然可以導入你需要的類,並通過簡單名稱引用它們:

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

// within some method: 
    Logger.getLogger(....); 
+0

thanku。它爲我工作。 – shardul