2016-03-05 21 views
0

*這個問題是不是重複其符號「非靜態方法不能從靜態上下文中引用?」,它涵蓋了不同的錯誤信息,這是「無法找到符號」。模糊編譯器錯誤「無法找到符號」,但沒有指定

我在與JCreator的顯示生成錯誤error: cannot find symbol,而不是指定什麼符號中發現的問題。

代碼:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 
public class FanTest extends JFrame 
{ 
    public FanTest() 
    { 
     setLayout(new GridBagLayout()); 
    //more stuff here 
    } 
    public void addCompsToGui(Container pane) 
    { 
     pane.setLayout(new GridBagLayout()); 
     GridBagConstraints c = new GridBagConstraints(); 
    //more stuff here 
    } 
    public static void main(String[] args) 
    { 
     FanTest gui = new FanTest(); 
     gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     gui.setSize(600,600); 
     gui.setTitle("Test Console for Fan"); 
     addCompstoGui(gui.getContentPane()); // error pointing to this line 
     gui.setVisible(true); 
    } 
} 

這是功課,我只是在尋找與一個錯誤的幫助,它的分辨率

+0

它是否給任何行號?我們需要更多的細節 – Ascalonian

+0

行號是218,在行後面註釋(從帖子底部開始第4個)。這就是編譯器給我的所有細節 – Azulflame

+0

stackTrace請因爲在這裏,我們不能確定哪一行是218? –

回答

4

mainstatic,沒有知名度的實例方法。更改

addCompstoGui(gui.getContentPane()); 

gui.addCompsToGui(gui.getContentPane()); 
+1

其實這叫做將無法工作或者是因爲該方法有一個大寫的「T」在它:addCompsToGui – Ascalonian

+1

你說得對,這不是回答之前。 http://stackoverflow.com/questions/290884/what-is-the-reason-behind-non-static-method-cannot-be-referenced-from-a-static – Tunaki

+0

@Ascalonian哎呀。修正了T. –

0
addCompstoGui(gui.getContentPane()); // java naming convention Error 

gui.addCompsToGui(gui.getContentPane()); //Successfully run becoz 

     //method name should be addCompsToGui and instance should associate with ths 
相關問題