File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes static import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static import" Watch "static import" New topic
Author

static import

suraj maurya
Greenhorn

Joined: Jan 17, 2013
Posts: 9
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...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575



Temp class reside in p2 or p1?
Manu Somasekhar
Ranch Hand

Joined: May 22, 2012
Posts: 44
Temp class belong to P1 not to P2
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
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: 44
Oopseee Yup Ritchie. You are correct.
suraj maurya
Greenhorn

Joined: Jan 17, 2013
Posts: 9
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: 38481
    
  23
Are you including the current directory in that classpath?
Is the p1 directory in that classpath?
suraj maurya
Greenhorn

Joined: Jan 17, 2013
Posts: 9
Campbell Ritchie wrote:Are you including the current directory in that classpath?
Is the p1 directory in that classpath?

no.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static import