• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Classpath Problem  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have set the classpath as .;d:\java\mypackage where lies a class called Pack.class. The source code is in not there in that directory and is like this.
package mypackage;
public class Pack{
Pack(){
System.out.println("mypackage.pack");
}
}
In directory d:\java I have a class Test.java which uses this Pack after importing all mypackage.*. The code is like this.
import mypackage.*;
public class Test {
public static void main(String[] args) {
Pack p = new Pack();
}
}
On compiling this I have got an error like
Error : No Constructor Matching Pack() found in class mypackage.pack.
Can anybody tell me how I can rectify this and explain why it is happening?. Thanks in advance.
 
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Raju,
You have two problems that I can see. First, modify your CLASSPATH to include the directory directly above the name of your package. The compiler cannot see your package because your CLASSPATH is d:\java\mypackage, it should be d:\java.
But, after you fix this you will see a compilation error saying that Pack() is not public in mypackage.Pack; cannot be accessed from outside of package.
To remedy this, make your Pack constructor public:
public Pack(){...}
Hope this helps.
By the way, you should really be outside on a Saturday
Michael
 
Raju Anand
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow It worked... The problem was with the declaration of the constructor Micheal. Thank you very much. Any way will come back soon with many doughts. Bye.
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!