This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Not able to create package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not able to create package" Watch "Not able to create package" New topic
Author

Not able to create package

Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
please note: i am using Gel as Java Editor

//<----first file:----->

package mypackage;

public class class1{
private int data;
class1(){
data=100;
}
public void func(){
System.out.println(data);
return;
}
}

//<-----Second file---->

import mypackage.*;

public class class2{
public static void main(String[] args){
class1 obj = new class1();
obj.func();
System.out.println("Done Successfully");
}
}

i am compling the first program and it should create the package inside the main working directory but ir is not creating.

and while compling the second file its unable to get the package and hence giving package doesn't exist error.

If some can help me out then please do reply soon.

Note that i am using Gel editor for java.


-------------------------------<br />you can't move ahead, unless you try for it.
Arnaud Burlet
Ranch Hand

Joined: Oct 08, 2004
Posts: 31
your class1.java should be in a directory named "mypackage",
your class2.java should be in the same directory as "mypackge" dir.



And to have your example work, you should declare class1 constructor as public.

Arnaud
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to create package