This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import problem

 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beats me.
 
sriman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that but it didnt work. Kept giving the same error.
 
sriman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sriman
I think what u say makes sense...but it still doesnt compile on my system.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic