Results 1 to 2 of 2
Thread: Error: cannot find symbol
- 08-06-2007, 06:11 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Error: cannot find symbol
Hello, After a little while of trying to figure this one out myself, I have given up on what should be a simple fix.
Error:
Java Code:GuiGuessingGameApp.java:7: cannot find symbol symbol : constructor GuiGuessingGameFrame() location: class GuiGuessingGameFrame GuiGuessingGameFrame frame = new GuiGuessingGameFrame();
Java Code:public class GuiGuessingGameTest { public static void main(String[] args) { GuiGuessingGameApp game = new GuiGuessingGameApp(); game.play(); } }Java Code:import java.util.Random; public class GuiGuessingGameApp { Random rnd = new Random(); int secretNumber = 0; GuiGuessingGameFrame frame = new GuiGuessingGameFrame(); public GuiGuessingGameApp() { secretNumber = 1 + rnd.nextInt(100); } public void play() { if (frame != null) frame.show(); } }
Thanks.Java Code:import javax.swing.JFrame; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class GuiGuessingGameFrame { JFrame myFrame = new JFrame(); JTextField myField = new JTextField("",2); JLabel myLabel = new JLabel("Enter A Guess"); JButton myButton = new JButton ("Guess!"); int mySecretNumber = -1; public GuiGuessingGameFrame(int mySecretNumber) { myFrame = new JFrame("Guessing Game!"); myFrame.setSize(200,95); myFrame.setVisible(true); myFrame.addWindowListener(new WinHandler()); Container contain = myFrame.getContentPane(); contain.setLayout(new FlowLayout()); contain.add(myField); contain.add(myButton); contain.add(myLabel); myButton.addActionListener(new ButtonListener()); } public void show() { myFrame.show(); } class ButtonListener implements ActionListener { public void actionPerformed( ActionEvent evt) { int guess = 0; try { guess = Integer.parseInt(myField.getText()); } catch (NumberFormatException e) { guess = 0; } System.out.println("The Number In The Text Box Is " + guess); } } } class WinHandler extends WindowAdapter { public void windowClosing(WindowEvent e) {System.exit(0);} }
- 08-06-2007, 08:12 PM #2
Your only constructor
takes an int argument. In your test class you are usingJava Code:public GuiGuessingGameFrame(int mySecretNumber)
a no–argument constructor which the class does not have.Java Code:new GuiGuessingGameApp();
If you do not explicitly define a constructor for a class java provides a no–argument constructor for it. If you provide any constructor that takes arguments you no longer get the default no–arg constructor from java. In this case you must add a no–argument constructor in the class.
Similar Threads
-
[SOLVED] Java Error: Cannot find Symbol...
By bobleny in forum New To JavaReplies: 8Last Post: 04-15-2008, 06:35 AM -
Programm Error: cannot find symbol Help?
By junix in forum New To JavaReplies: 2Last Post: 12-10-2007, 05:30 AM -
cannot find symbol class error
By po0oker in forum New To JavaReplies: 5Last Post: 10-31-2007, 02:52 PM -
Error: cannot find symbol
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:39 AM -
Error: cannot find symbol constructor
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 08:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks