L
lonelyplanet999
I have below .java files located under c:\javapgm\pack4\
File: NoPack.java
-----------------
package pack4;
public class NoPack { }
class Dummy1 {}
class Dummy2 {}
File: NoPack2.java
------------------
package pack4;
public class NoPack2 {
Dummy3 d3;
void print1() {
System.out.println("new Dummy3="+(new Dummy3()));
}
public void print2() {
Dummy4 d4=new Dummy4(); System.out.println("new Dummy4="+d4);
}
public void print3() {
Dummy1 d1 = new Dummy1(); System.out.println("Dummy1 instance
created in NoPack2 using NoPack.java is "+d1);
}
public void print4() {
System.out.println("Dummy2 instance created in NoPack2 using
NoPack.java is "+(new Dummy2()));
}
}
class Dummy3 {}
class Dummy4 {}
File: AccessLocal.java
----------------------
package pack4;
public class AccessLocal {
public static void main (String [] args) {
System.out.println("Accessing NoPack.java");
NoPack np = new NoPack();
System.out.println("NoPack instance "+np+" created");
NoPack2 np2 = new NoPack2();
System.out.println("NoPack2 instance "+np+" created");
Dummy1 d1 = new Dummy1();
System.out.println("Dummy1 instance "+d1+" created");
Dummy2 d2 = new Dummy2();
System.out.println("Dummy2 instance "+d2+" created");
Dummy3 d3 = new Dummy3();
System.out.println("Dummy3 instance "+d3+" created");
Dummy4 d4 = new Dummy4();
System.out.println("Dummy4 instance "+d4+" created");
System.out.print("np2.print1() ");
np2.print1();
System.out.print("np2.print2() ");
np2.print2();
System.out.print("np2.print3() ");
np2.print3();
System.out.print("np2.print4() ");
np2.print4();
np2.d3 = new Dummy3();
System.out.println("NoPack2.Dummy3 instance "+np2.d3+" created");
}
}
I called c:\j2sdk1.4.1_01\bin\javac pack4\NoPack.java
c:\j2sdk1.4.1_01\bin\javac pack4\NoPack2.java
c:\j2sdk1.4.1_01\bin\javac pack4\AccessLocal.java
from c:\javapgm, all returned no error.
However as I called c:\j2sdk1.4.1_01\bin\java pack4\AccessLocal from
c:\javapgm, java returned exception in thread "main"
java.lang.NoClassDefFoundError: pack4\AccessLocal (wrong name:
pack/AccessLocal) and program wasn't started.
I would like to know why this will happen ?
Is there no way to run main() if it being defined in a .java file
belonging to a package having more than one .java file ? I'm sure if I
placed content of all 3 above .java files in one .java, both
compilation & execution will succeed. Also, because I want AccessLocal
class in the same package as others, I couldn't place AccessLocal.java
in c:\javapgm. Otherwise, the compiler will complain.
Similar problem appeared in my previously asked question
http://groups.google.com.hk/groups?...t6lb%246gt%241%40hood.uits.indiana.edu&rnum=1
where I coded a class Level1 under the file c:\javapgm\l1\.
Compilation succeeded too but program execution returned exception
same as above type.
File: Level1.java, compiled & ran under c:\javapgm similar to above.
--------------------------------------------------------------------
package l1;
public class Level1 {
public static void main (String [] args) {
System.out.println("Level 1");
}
}
In this case, program execution always fail on run time. Is there no
way to associate a package name with a .java where I want it to be
executed i.e. an runnable main embeded like above ?
HELP! HELP!! HELP!!! HELP!!!! HELP!!!!!
File: NoPack.java
-----------------
package pack4;
public class NoPack { }
class Dummy1 {}
class Dummy2 {}
File: NoPack2.java
------------------
package pack4;
public class NoPack2 {
Dummy3 d3;
void print1() {
System.out.println("new Dummy3="+(new Dummy3()));
}
public void print2() {
Dummy4 d4=new Dummy4(); System.out.println("new Dummy4="+d4);
}
public void print3() {
Dummy1 d1 = new Dummy1(); System.out.println("Dummy1 instance
created in NoPack2 using NoPack.java is "+d1);
}
public void print4() {
System.out.println("Dummy2 instance created in NoPack2 using
NoPack.java is "+(new Dummy2()));
}
}
class Dummy3 {}
class Dummy4 {}
File: AccessLocal.java
----------------------
package pack4;
public class AccessLocal {
public static void main (String [] args) {
System.out.println("Accessing NoPack.java");
NoPack np = new NoPack();
System.out.println("NoPack instance "+np+" created");
NoPack2 np2 = new NoPack2();
System.out.println("NoPack2 instance "+np+" created");
Dummy1 d1 = new Dummy1();
System.out.println("Dummy1 instance "+d1+" created");
Dummy2 d2 = new Dummy2();
System.out.println("Dummy2 instance "+d2+" created");
Dummy3 d3 = new Dummy3();
System.out.println("Dummy3 instance "+d3+" created");
Dummy4 d4 = new Dummy4();
System.out.println("Dummy4 instance "+d4+" created");
System.out.print("np2.print1() ");
np2.print1();
System.out.print("np2.print2() ");
np2.print2();
System.out.print("np2.print3() ");
np2.print3();
System.out.print("np2.print4() ");
np2.print4();
np2.d3 = new Dummy3();
System.out.println("NoPack2.Dummy3 instance "+np2.d3+" created");
}
}
I called c:\j2sdk1.4.1_01\bin\javac pack4\NoPack.java
c:\j2sdk1.4.1_01\bin\javac pack4\NoPack2.java
c:\j2sdk1.4.1_01\bin\javac pack4\AccessLocal.java
from c:\javapgm, all returned no error.
However as I called c:\j2sdk1.4.1_01\bin\java pack4\AccessLocal from
c:\javapgm, java returned exception in thread "main"
java.lang.NoClassDefFoundError: pack4\AccessLocal (wrong name:
pack/AccessLocal) and program wasn't started.
I would like to know why this will happen ?
Is there no way to run main() if it being defined in a .java file
belonging to a package having more than one .java file ? I'm sure if I
placed content of all 3 above .java files in one .java, both
compilation & execution will succeed. Also, because I want AccessLocal
class in the same package as others, I couldn't place AccessLocal.java
in c:\javapgm. Otherwise, the compiler will complain.
Similar problem appeared in my previously asked question
http://groups.google.com.hk/groups?...t6lb%246gt%241%40hood.uits.indiana.edu&rnum=1
where I coded a class Level1 under the file c:\javapgm\l1\.
Compilation succeeded too but program execution returned exception
same as above type.
File: Level1.java, compiled & ran under c:\javapgm similar to above.
--------------------------------------------------------------------
package l1;
public class Level1 {
public static void main (String [] args) {
System.out.println("Level 1");
}
}
In this case, program execution always fail on run time. Is there no
way to associate a package name with a .java where I want it to be
executed i.e. an runnable main embeded like above ?
HELP! HELP!! HELP!!! HELP!!!! HELP!!!!!