Results 1 to 8 of 8
Thread: Still Cannot Find Symbol
- 08-21-2013, 04:26 AM #1
Senior Member
- Join Date
- Jul 2013
- Location
- Wisconsin, USA
- Posts
- 106
- Rep Power
- 0
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); } }
http://docs.oracle.com/javase/tutori...O/objects.htmlLast edited by SamJava_the_Hut; 08-21-2013 at 04:33 AM.
- 08-21-2013, 05:09 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-21-2013, 08:31 AM #3
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
- 08-21-2013, 04:35 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-21-2013, 04:42 PM #5
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Still Cannot Find Symbol
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-21-2013, 04:58 PM #6
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-24-2013, 12:07 AM #7
Senior Member
- Join Date
- Jul 2013
- Location
- Wisconsin, USA
- Posts
- 106
- Rep Power
- 0
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?
- 08-24-2013, 12:27 AM #8
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
cannot find symbol
By Ericyue in forum New To JavaReplies: 1Last Post: 04-06-2012, 06:00 AM -
Cannot find symbol
By shane5317 in forum AWT / SwingReplies: 3Last Post: 03-02-2011, 12:36 PM -
Cannot find symbol
By Johanis in forum New To JavaReplies: 19Last Post: 11-04-2010, 09:13 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 09:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 09:30 AM
Bookmarks