Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Still Cannot Find Symbol

    I declared the fields in the main method of my code, but it still says "Cannot Find Symbol". Here's the code:

    Java Code:
    /*
     * Drilling into the basics of object creation.
     */
    package chapter4;
    
    /**
     *
     * @author User
     */
    public class CreateObjectDemo {
        
        public static void main(String[] args) {
    		
            int Rectangle;
            int Point;
                    
            // Declare and create a point object and two rectangle objects.
            Point originOne = new Point(23, 94);
            Rectangle rectOne = new Rectangle(originOne, 100, 200);
            Rectangle rectTwo = new Rectangle(50, 100);
            
            /*
             * WTF? I declared both Rectangle and Point above, and I'm still getting
             * red (between this block comment and int Point;). Why?
             */
    		
            // display rectOne's width, height, and area
            System.out.println("Width of rectOne: " + rectOne.width);
            System.out.println("Height of rectOne: " + rectOne.height);
            System.out.println("Area of rectOne: " + rectOne.getArea());
    		
            // set rectTwo's position
            rectTwo.origin = originOne;
    		
            // display rectTwo's position
            System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
            System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);
    		
            // move rectTwo and display its new position
            rectTwo.move(40, 72);
            System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
            System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);
        }
        
    }
    I got this code from here:

    http://docs.oracle.com/javase/tutori...O/objects.html
    Last edited by SamJava_the_Hut; 08-21-2013 at 03:33 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: Still Cannot Find Symbol

    I don't see any import statements. Nor in the JDK Doc did I see a constructor of Rectangle(Point, int, int).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Still Cannot Find Symbol

    From java tutorial :
    " You will need all three source files to compile this program. "
    http://docs.oracle.com/javase/tutori...bjectDemo.java
    http://docs.oracle.com/javase/tutori...les/Point.java
    http://docs.oracle.com/javase/tutori...Rectangle.java
    Hope it will work now

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: Still Cannot Find Symbol

    You don't need any source files other than the OP's. Just the pre-compiled classes which are available via imports.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,001
    Rep Power
    6

    Default Re: Still Cannot Find Symbol

    Quote Originally Posted by jim829 View Post
    You don't need any source files other than the OP's. Just the pre-compiled classes which are available via imports.

    Regards,
    Jim
    Yes but how do you get those precompiled classes when you don't download their sources and compile them? Even though the names mights suggest it, they're not the standard AWT Point and Rectangle classes.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: Still Cannot Find Symbol

    Yeah! My response was probably a bit hasty. I figured it was too much of a coincidence to mimic all the constructors exactly except one. And not importing the classes would have been a possible cause.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: Still Cannot Find Symbol

    I'm using Netbeans IDE to write my code. Are each of my project's packages only supposed to have one main class .java file? If so, does that mean I can only have one super class per package?

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: Still Cannot Find Symbol

    A package may have many classes and a project may involve many packages. The class which contains the static main method is typcially the point of entry when the app is loaded and run by the JVM.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. cannot find symbol
    By Ericyue in forum New To Java
    Replies: 1
    Last Post: 04-06-2012, 05:00 AM
  2. Cannot find symbol
    By shane5317 in forum AWT / Swing
    Replies: 3
    Last Post: 03-02-2011, 11:36 AM
  3. Cannot find symbol
    By Johanis in forum New To Java
    Replies: 19
    Last Post: 11-04-2010, 08:13 PM
  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
  •