Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static import

 
suraj maurya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Temp class reside in p2 or p1?
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Temp class belong to P1 not to P2
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oopseee Yup Ritchie. You are correct.
 
suraj maurya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you including the current directory in that classpath?
Is the p1 directory in that classpath?
 
suraj maurya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Are you including the current directory in that classpath?
Is the p1 directory in that classpath?

no.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic