aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Not able to create package
 
Similar Threads
Kind Attn:Marcus Green - Pl. clear doubt
package problem
Two Packages in the Same Directory?
Package & Compilation Problem
Confusion Question