• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

cannot find symbol error during compilation

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have two files 1) MyClass.java 2)Another.java

Directory Structure D:\chap10\com\foo

Both files are in foo folder

MyClass.java contain following code

package com.foo;
public class MyClass
{
public void hi() {System.out.println("hi?");}
}

Another.java contain following code

package com.foo;
import com.foo.*;
public class Another {
void go() {
MyClass m1 = new MyClass();
com.foo.MyClass m2 = new com.foo.MyClass();
m1.hi();
m2.hi();
}

public static void main(String [] args)
{
Another an = new Another();
an.go();
}
}

Following error occur when Another.java is compiled

D:\ExamPractice\com\foo>javac Another.java
Another.java:9: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m1 = new MyClass();
^
Another.java:9: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m1 = new MyClass();
^
Another.java:10: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m2 = new MyClass();
^
Another.java:10: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m2 = new MyClass();
^
4 errors

Refer to example on page 769 SCJP study guide by Kathy Sierra & Bert Bates
 
author
Posts: 23937
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your classpath is likely not set... trying compiling as so...

D:\ExamPractice>javac com\foo\Another.java



Henry
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any need to for the import statement when both the classes are in the same package?
wont compiler give error. I use eclipse and it just dont let me write this kind of import statement.
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes in the same package we don't need import statement.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic