I have a folder named packages.I made Temp.java and i wrote code
and parallel to Temp.java I created another file Temp1.java as follows
then I first compiled Temp.java and after that I set the classpath and when I try to compile Temp1.java it shows the following errors
Temp1.java:2: <identifier> expected
import static p2.Temp.x;
^
Temp1.java:2: '.' expected
import static p2.Temp.x;
^
Temp1.java:7: cannot resolve symbol
symbol : variable x
location: class p2.Temp1
System.out.println(x);
^
3 errors
I dont understand why is it coming...Please help me out. If I am wrong then tell me the correct way of static import...
Manu Somasekhar wrote:Temp class belong to P1 not to P2
Not P1 and P2 but p1 and p2. Remember case‑sensitivity.
Manu Somasekhar
Ranch Hand
Joined: May 22, 2012
Posts: 30
posted
0
Oopseee Yup Ritchie. You are correct.
suraj maurya
Greenhorn
Joined: Jan 17, 2013
Posts: 6
posted
0
Manu Somasekhar wrote:Oopseee Yup Ritchie. You are correct.
sorry that was a mistake....now I will exactly explain my problem.
And
I have Temp.java in package p1 and Temp1.java in package p2 in location E:\important\java programs\packages
then I make Temp.java run using javac -d . Temp.java
and after that I set classpath using command as follows
set classpath=E:\important\java programs\packages
and then i try to compile Temp1.java and it shows the following errors
Temp1.java:2: <identifier> expected
import static p1.Temp.x;
^
Temp1.java:2: '.' expected
import static p1.Temp.x;
^
Temp1.java:7: cannot resolve symbol
symbol : variable x
location: class p2.Temp1
System.out.println(x);
^
3 errors
please tell me wheather I am wrong at any step or not?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32839
4
posted
0
Are you including the current directory in that classpath?
Is the p1 directory in that classpath?
suraj maurya
Greenhorn
Joined: Jan 17, 2013
Posts: 6
posted
0
Campbell Ritchie wrote:Are you including the current directory in that classpath?
Is the p1 directory in that classpath?