0

*This question is not a duplicate of "non-static method cannot be referenced from a static context?", and it covers a different error message, which is "Cannot find symbol".

I'm having an issue with JCreator showing the build error error: cannot find symbol, while not specifying what symbol is found.

code:

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

This is homework, and I'm only looking for help with the one error and it's resolution

Azulflame
  • 1,534
  • 2
  • 15
  • 30

2 Answers2

4

main is static and has no visibility to instance methods. Change

addCompstoGui(gui.getContentPane());

to

gui.addCompsToGui(gui.getContentPane());
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
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
Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52