Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2012
    Posts
    20
    Rep Power
    0

    Default Debugging: Cannot Find Symbol

    I am debugging some code and for the love of god can not figure out why Im getting this error. The code is:

    PHP Code:
    // DebugThirteen1
    // Creates a frame with a specified size
    // Twice as tall as wide
    import javax.swing.*;
    public class DebugThirteen1 extends JFrame
    {
       public DebugThirteen1(int size)
       {
    	super("This is my frame");
    	size = 200;  //Set size
    	setSize(size, size * 2);
    	setVisible(true); //Added this line to set frame to visible
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Missing period between JFrame and EXIT
       }
       public static void main(String[] args)
       {
       DebugThirteen1 frame = new DebugThirteen1(); //Missing word new
       } 
    }
    The error is:

    C:\Users\Tyler\Documents\School Work\CIS280\Project 9>javac DebugThirteen1.java
    DebugThirteen1.java:17: cannot find symbol
    symbol : constructor DebugThirteen1()
    location: class DebugThirteen1
    JFrame DebugThirteen1 = new DebugThirteen1(); //Missing word new
    ^
    1 error
    I cant figure out why this error is coming up.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Debugging: Cannot Find Symbol

    You receive the error because you don't have a default constructor in you class. Default constructor is constructor without parameters. Because of this you can call the default constructor using the new operator to create an instance of that class.

    In your class you only have a constructor that accept a single parameter with the integer type. That's mean when creating a new instance you have to call this constructor. You should do:

    Java Code:
        DebugThirteen1 frame = new DebugThirteen1(100);
    Instead of:

    Java Code:
        DebugThirteen1 frame = new DebugThirteen1();
    Which will produce an error because the constructor is not available.

  3. #3
    Join Date
    Oct 2012
    Posts
    20
    Rep Power
    0

    Default Re: Debugging: Cannot Find Symbol

    Thank you for the explanation. That makes sense. So how would I go about getting rid of the necessary int argument in my Main? Would I just move size to the class?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Debugging: Cannot Find Symbol

    You can always provide a default constructor in your class. And then define the default size of the frame in this constructor. So when you create a new instance using default constructor it will always use the default frame size.

  5. #5
    Join Date
    Oct 2012
    Posts
    20
    Rep Power
    0

    Default Re: Debugging: Cannot Find Symbol

    This is what I did so I only had to define size 1 time rather than through an argument as well.

    PHP Code:
    // DebugThirteen1
    // Creates a frame with a specified size
    // Twice as tall as wide
    import javax.swing.*;
    public class DebugThirteen1 extends JFrame
    {
    size = 200;  //Set size
       public DebugThirteen1(int size)
       {
        super("This is my frame");
      
        setSize(size, size * 2);
        setVisible(true); //Added this line to set frame to visible
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Missing period between JFrame and EXIT
       }
       public static void main(String[] args)
       {
       DebugThirteen1 frame = new DebugThirteen1(); //Missing word new
       }
    }

Similar Threads

  1. Cannot find symbol
    By Eleeist in forum New To Java
    Replies: 5
    Last Post: 01-22-2012, 08:36 PM
  2. Cannot Find Symbol
    By Promisha in forum New To Java
    Replies: 10
    Last Post: 03-30-2011, 02:11 AM
  3. Can not find symbol ???
    By AliceNewbie in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 01:44 AM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •