This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Import problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Import problem" Watch "Import problem" New topic
Author

Import problem

Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
I have these 2 files:
My.java-->
-----------------------------
package San;
public class My {
public int i;
public void MyMethod(){
i=1;
System.out.println("Here");
}
}
------------------------------
My1.java->
----------------------------
package San;
import San.*;
public class My1 {
My my;
public void MyMethod1(){
int i1=1;
}
}

-------------------------
I get following error on compiling:
My1.java:4: cannot resolve symbol
symbol : class My
location: class San.My1
My my;
^
1 error..
WHAT CAN I DO TO COMPILE AND RUN BOTH CLASSES?
kishor rao
Ranch Hand

Joined: Dec 10, 2002
Posts: 35
Beats me.
sriman
Greenhorn

Joined: Feb 05, 2003
Posts: 6
Please compile the My.java file first.
Then compile My1.java
or else give like this
javac My*.java

U can see the successful compilation..
Is it ok??? Thanks
kishor rao
Ranch Hand

Joined: Dec 10, 2002
Posts: 35
I tried that but it didnt work. Kept giving the same error.
sriman
Greenhorn

Joined: Feb 05, 2003
Posts: 6
Ok cool...
I hope ur java source files will be in san directory..
Try this now
javac -d My.java
javac -d My1.java
This command compile java files and create a folder san and put the class files inside..
This will work out...try out and lemme know
Thanx
sriman
Greenhorn

Joined: Feb 05, 2003
Posts: 6
Pls ignore last one...hava look at this
Try this now
javac -d . My.java
javac -d . My1.java
or
javac -d . My*.java
This command compile java files and create a folder san and put the class files inside..
This will work out...try out and lemme know
Thanx
kishor rao
Ranch Hand

Joined: Dec 10, 2002
Posts: 35
That does it. But the My.class file anyway goes to the San directory(i.e. wherever the My.java file is.) How does including -d make it work?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Sanjay (and/or Kishor?),
First, remove the "import" statement from the "My1.java" file -- it is redundant.
Next, I suggest you look at the following web page:
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
[Assuming you haven't already -- but from your posting, I'm almost certain that you haven't! ]
Hope this helps you.
Good Luck,
Avi.
sriman
Greenhorn

Joined: Feb 05, 2003
Posts: 6
Hi Kishore,
javac -d dirname filename.java
In this
-d is an option where do u want to put ur files..
Next to this u should specify the dir..
If u put dot(.) then it will take current dir as an argument..
U delete all class files and dir created by javac.
and try
javac -d . My*.java command
It will create san dir u have mentioned aa package.
put ur class file into it.

any more clarification...Thanx
kishor rao
Ranch Hand

Joined: Dec 10, 2002
Posts: 35
This is what i have done and it doesnt work:
1. Create a San folder in <path> and save both the .java files in it.
2. Compile My.java as in
javac <path>\San\My.java
This creates the My.class file in <path>\San
3. Compile My1.java similarly as above.
This compilation gives an error even though all three files(My.java, My1.java, and My.class) are in <path>\San.
This is waht javac does with the -d option isnt it? But it doesnt work when i create the directory myself. Why?
sriman
Greenhorn

Joined: Feb 05, 2003
Posts: 6
Bcos, u r referring My class in My1.java.. is in it !!!
so that it is keep an giving error..
It was looking for san.My class..
But u r already in folder named san and trying to compile..so obviously the My1.java looking c:/san/san/My.class...
But u r not having such dir...
u r having ur first class in this c:\san\My.class dir..
So do one thing....
Copy ur My1.java in c:
now compile using javac alone...it should compile...
Tnx
kishor rao
Ranch Hand

Joined: Dec 10, 2002
Posts: 35
Hi Sriman
I think what u say makes sense...but it still doesnt compile on my system.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import problem
 
Similar Threads
input reading problem
Data lost when writing object to a file
running a servlet without IDE
Some problems with testing with JUnit
final array