0

*这个问题不是“non-static method cannot be referenced from a static context?”的重复,它涵盖了不同的错误消息,即“Cannot find symbol”。

我在 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);
    }
}

这是家庭作业,我只是在寻求解决一个错误的帮助

4

2 回答 2

4

mainstatic并且对实例方法没有可见性。改变

addCompstoGui(gui.getContentPane());

gui.addCompsToGui(gui.getContentPane());
于 2016-03-05T23:20:52.337 回答
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
于 2016-03-05T23:24:43.560 回答