• Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot find symbol  RSS feed

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compile two files Protection.java and SamePackage.java
Sampackage.java is giving following error

SamePackage.java:4: error: cannot find symbol
Protection p = new Protection();
^
symbol: class Protection
location: class SamePackage
SamePackage.java:4: error: cannot find symbol
Protection p = new Protection();
^
symbol: class Protection
location: class SamePackage
2 errors



Here is the code...


Protection.java



SamePackage.java



How do I rectify these Errors ? Please Help Me !!!
 
Pablo Reyes
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You forgot to import Mypack.Protection from SamePackage.java.

The fact that they are in the same package doesn't mean that you can avoid the import part.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pablo Reyes wrote:You forgot to import Mypack.Protection from SamePackage.java.

The fact that they are in the same package doesn't mean that you can avoid the import part.

Yes it does.
The problem is more likely related to the classpath. @OP: Is the directory that the Mypack directory is in, in your classpath ?
 
Pablo Reyes
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what I was thinking about when I said that. Of course it does, sorry.

Joanne is right.
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classpath was not set
Thanks for Replying !!
Problem Solved !!
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't feel bad Pablo. i might have jumped to the same wrong answer myself. having a package statement does make it different than no package statement. for example you no longer go to the default folder and say java MyClass. you have to go to the next folder up and say java myPackage/MyClass. there are probably other differences as well.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!