The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files


一段簡單程序, frame.add(lbl);出現 問題。 也不知道為什么就是這里, 而我Ctrl + Shift + T 確實也是沒有發現 JComponent 。

public void displayImage(String title, Image img, int x, int y)
{
    ImageIcon icon=new ImageIcon(img);
    JFrame frame=new JFrame(title);
    JLabel lbl=new JLabel(icon);
    frame.add(lbl);//  ERROR
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocation(x, y);
    frame.setVisible(true);
}

奇了怪了!我猜是jdk版本的問題,但是為什么呢? 難道不能用jdk8 ? 可是項目的其他代碼都是依賴jdk8 的?

網上查看半天沒有找到解決方案! stackoverflow 也沒有! 郁悶! 后面偶然發現這個 :

http://blogs.candoerz.com/question/155925/java-swing-component-cannot-be-resolved.aspx

我大概明白了,應該還是jdk8 在myeclipse10 的不兼容的問題。 具體來說是我的 myeclipse10 的java compliation level 只能是 7, 所以。。。

換成 ideaj, 問題解決! 又是 jdk8 在myeclipse 的不兼容的問題啊!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM