当前位置: 技术问答>java相关
问一个暴简单的问题。有关java的package参数的
来源: 互联网 发布时间:2015-11-18
本文导语: 我有下列的程序: //: Parcel3.java // Returning a handle to an inner class package c07.parcel3; abstract class Contents { abstract public int value(); } interface Destination { String readLabel(); } public class Parcel3 { private class PCon...
我有下列的程序:
//: Parcel3.java
// Returning a handle to an inner class
package c07.parcel3;
abstract class Contents {
abstract public int value();
}
interface Destination {
String readLabel();
}
public class Parcel3 {
private class PContents extends Contents {
private int i = 11;
public int value() { return i; }
}
protected class PDestination
implements Destination {
private String label;
private PDestination(String whereTo) {
label = whereTo;
}
public String readLabel() { return label; }
}
public Destination dest(String s) {
return new PDestination(s);
}
public Contents cont() {
return new PContents();
}
}
class Test {
public static void main(String[] args) {
Parcel3 p = new Parcel3();
Contents c = p.cont();
Destination d = p.dest("Tanzania");
// Illegal -- can't access private class:
//! Parcel3.PContents c = p.new PContents();
}
} ///:~
我把他放在jdk的根目录下编译通过,但是运行的时候就回报如下错误:
C:J2SDK1~1.0-R>java Parcel3
Exception in thread "main" java.lang.NoClassDefFoundError: Parcel3 (wrong name:
c07/parcel3/Parcel3)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
请各位达人指教一下 谢谢
//: Parcel3.java
// Returning a handle to an inner class
package c07.parcel3;
abstract class Contents {
abstract public int value();
}
interface Destination {
String readLabel();
}
public class Parcel3 {
private class PContents extends Contents {
private int i = 11;
public int value() { return i; }
}
protected class PDestination
implements Destination {
private String label;
private PDestination(String whereTo) {
label = whereTo;
}
public String readLabel() { return label; }
}
public Destination dest(String s) {
return new PDestination(s);
}
public Contents cont() {
return new PContents();
}
}
class Test {
public static void main(String[] args) {
Parcel3 p = new Parcel3();
Contents c = p.cont();
Destination d = p.dest("Tanzania");
// Illegal -- can't access private class:
//! Parcel3.PContents c = p.new PContents();
}
} ///:~
我把他放在jdk的根目录下编译通过,但是运行的时候就回报如下错误:
C:J2SDK1~1.0-R>java Parcel3
Exception in thread "main" java.lang.NoClassDefFoundError: Parcel3 (wrong name:
c07/parcel3/Parcel3)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
请各位达人指教一下 谢谢
|
package问题
你新建一个这种路径下的目录:
c07/parcel3/
将Parcel3文件放入其下,然后执行:java c07.parcel3.Parcel3
注意,如果不是在c07目录下执行此命令,则必须将c07的绝对路径放入classpath环境变量中
btw:注意classpath环境变量中带上当前目录即classpath=.;……
你新建一个这种路径下的目录:
c07/parcel3/
将Parcel3文件放入其下,然后执行:java c07.parcel3.Parcel3
注意,如果不是在c07目录下执行此命令,则必须将c07的绝对路径放入classpath环境变量中
btw:注意classpath环境变量中带上当前目录即classpath=.;……
|
Exception in thread "main" java.lang.NoClassDefFoundError: Parcel3 (wrong name:
而你的程序
package c07.parcel3;
---------------------------大小些的问题 Parce13...parce13
而你的程序
package c07.parcel3;
---------------------------大小些的问题 Parce13...parce13