Results 1 to 8 of 8
Thread: Object cannot find symbol.
- 03-02-2011, 10:17 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Object cannot find symbol. Solved
I'm new to Java and I've been going through the book Head-First-Java 2nd edition. I'm learning about objects and how to call them from within a different class, I follow the book exactly, but I'm getting a cannot find symbol error.
Here is my code.
Java Code:class Movie { String title; String genre; int rating; void playIt() { System.out.println("Playing the movie"); } }I can compile Movie.java properly, but when I try to compile MovieTestDrive.java, I get this output.Java Code:public class MovieTestDrive { public static void main(String[] args) { Movie one = new Movie(); one.title = "Gone with the Stock"; one.genre = "Tragic"; one.rating = -2; Movie two = new Movie(); two.title = "Lost in Cubicle Space"; two.genre = "Comedy"; two.rating = 5; two.playIt(); Movie three = new Movie(); three.title = "Byte Club"; three.genre = "Tragic but ultimately uplifting"; three.rating = 127; } }
..\sample\test\MovieTestDrive.java:3: cannot find symbol
Movie one = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
..\sample\test\MovieTestDrive.java:3: cannot find symbol
Movie one = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
..\sample\test\MovieTestDrive.java:7: cannot find symbol
Movie two = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
..\sample\test\MovieTestDrive.java:7: cannot find symbol
Movie two = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
..\sample\test\MovieTestDrive.java:12: cannot find symbol
Movie three = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
..\sample\test\MovieTestDrive.java:12: cannot find symbol
Movie three = new Movie();
^
symbol: class Movie
location: class MovieTestDrive
6 errors
ThanksLast edited by Acadian; 03-02-2011 at 11:18 PM. Reason: Solved
- 03-02-2011, 10:33 PM #2
Are the two .java files in the same directory? If not you will need to use an import statement or simply place them in the same folder.
- 03-02-2011, 10:35 PM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
As junky stated, put them in the same directory and your code should work. By the way, head first java does a great job covering stuff. If you need any help, dont hesitAte to come ask questions here, also, feel free to send memmsges if needed for help.
Last edited by sunde887; 03-02-2011 at 10:40 PM.
- 03-02-2011, 10:35 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Yes they are both in a directory in my jdk root called sample\test I am invoking javac from the bin directory on the command line like this.
javac ../sample/test/Movie.java then when that compiles ok
javac ../sample/test/MovieTestDrive.java
in a command prompt.
- 03-02-2011, 10:45 PM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
It might be easier to save them in a new directory and then cd to the directory and then compile like that, try cding to the directory containing them in the root directory you saved them in and try compiling like that
- 03-02-2011, 10:53 PM #6
That won't work as it is trying to find the Movie class in the current working directory ie the bin directory. A better approach is to modify your environment variable so it know where the java and javac exe's are. Then you cd to the directory where your files are to compile and run.
- 03-02-2011, 11:14 PM #7
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Thanks, that was the problem :)
- 03-03-2011, 08:33 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Cannot find symbol
By Johanis in forum New To JavaReplies: 18Last Post: 11-09-2010, 08:34 PM -
Still cannot find symbol!
By Johanis in forum New To JavaReplies: 1Last Post: 11-04-2010, 04:32 PM -
Can not find symbol ???
By AliceNewbie in forum New To JavaReplies: 1Last Post: 02-17-2010, 01:44 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08: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, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks