Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 08:11 PM
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
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:

Code:
GuiGuessingGameApp.java:7: cannot find symbol symbol : constructor GuiGuessingGameFrame() location: class GuiGuessingGameFrame GuiGuessingGameFrame frame = new GuiGuessingGameFrame();
Code:
public class GuiGuessingGameTest { public static void main(String[] args) { GuiGuessingGameApp game = new GuiGuessingGameApp(); game.play(); } }
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(); } }

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);} }
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 10:12 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Your only constructor
Code:
public GuiGuessingGameFrame(int mySecretNumber)
takes an int argument. In your test class you are using
Code:
new GuiGuessingGameApp();
a no–argument constructor which the class does not have.
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java Error: Cannot find Symbol... bobleny New To Java 8 04-15-2008 08:35 AM
Programm Error: cannot find symbol Help? junix New To Java 2 12-10-2007 07:30 AM
cannot find symbol class error po0oker New To Java 5 10-31-2007 04:52 PM
Error: cannot find symbol silvia New To Java 1 08-07-2007 07:39 AM
Error: cannot find symbol constructor zoe New To Java 1 07-24-2007 10:24 PM


All times are GMT +3. The time now is 02:30 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org