• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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: 23956
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.
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic