Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing packages: error again

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am compiling my programs using ONLY the console. I get an error which i will show below. The following is my directory structure :
floor1 is a folder. floor2 and floor3 are packages.The rest are classes.


Now the source code for all the classes :


The above class compiles successfully with path as shown below :
C:\rb\floor1>javac Class1.java
C:\rb\floor1>


error !

The above class FAILS to compile WHEN i go to its folder and try to compile !. Here is the error :
C:\rb\floor1\floor2>javac Class2.java
Class2.java:2: package floor2.floor3 does not exist
import floor2.floor3.*;
^
1 error
C:\rb\floor1\floor2>


The above class compiles successfully with path as shown below :
C:\rb\floor1\floor2\floor3>javac Class3.java
C:\rb\floor1\floor2\floor3>


PS : I have tried to make it as easy as possible to review my code. Please let me know if its too verbose or if it could be improved.
regards rb
 
Sudipta Laha
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class you are compiling has an import statement floor2.floor3.*, but you are compiling inside the floor2 folder. So its giving error. Please modify your import statement and try to compile.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The import statements are fine. Tha problem is the same as in your other post. You need to include the C:\rb\floor1 directory in your classpath. This is why you should specify the classpath on the command line and not in the CLASSPATH environment variable. It's going to be different for each of your projects.
 
prem pillai
Ranch Hand
Posts: 87
Java Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Sudip Bose wrote:


Even if not directly related to this subject; You can create such char representations using Tree command. In windows you just type "tree /F"


 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prem pillai wrote:
Rahul Sudip Bose wrote:
Even if not directly related to this subject; You can create such char representations using Tree command. In windows you just type "tree /F"


Thanks, you lifted a major burden off me ! God, do i need to learn DOS also ? can you suggest a good book/website to learn such stuff ?
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:The import statements are fine. Tha problem is the same as in your other post. You need to include the C:\rb\floor1 directory in your classpath. This is why you should specify the classpath on the command line and not in the CLASSPATH environment variable. It's going to be different for each of your projects.


If its already set in environment variables, can i reset it temporarily in CMD ? or i have to delete the variable ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Sudip Bose wrote:If its already set in environment variables, can i reset it temporarily in CMD ? or i have to delete the variable ?
Yes. If you use the -cp command line option the CLASSPATH environment variable will be ignored.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic