• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static import

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Temp class reside in p2 or p1?
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Temp class belong to P1 not to P2
 
Marshal
Posts: 79151
377
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oopseee Yup Ritchie. You are correct.
 
suraj maurya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic