NetBeans v. SDK

R

Richard Bell

I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks
 
R

Ryan Stewart

Richard Bell said:
I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That goes
for subdirectories of the mounted directories. They are considered packages
and must be imported.
 
R

Richard Bell

Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.
 
R

Ryan Stewart

*fix top post*
Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That goes
for subdirectories of the mounted directories. They are considered packages
and must be imported.

Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.
What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?
 
R

Richard Bell

*fix top post*
I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That goes
for subdirectories of the mounted directories. They are considered packages
and must be imported.

Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.
What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?

Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.
 
R

Ryan Stewart

Richard Bell said:
*fix top post*
On Sun, 15 Feb 2004 21:00:56 -0600, "Ryan Stewart"


I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java.
That
goes
for subdirectories of the mounted directories. They are considered packages
and must be imported.


Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.
What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?

Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.
If you're working in NetBeans, you have a directory mounted. In the left
hand pane (Explorer), click the "Filesystems" tab at the bottom. This will
show you all mounted directories. You can mount a new one by right clicking
on the "Filesystem" thing at the top of the list/tree. From what you've
said, I would guess that you have "My Documents" mounted. That means that
your "My Documents" folder is in your classpath when you execute something.
The LearnJava and RichardFirstPackage folders are not. Anything in a
subdirectory of My Documents is considered by Java to be in a package and
*must* include a package statement. What you're doing is basically like
trying to run "java RichardFirstPackage" from My Documents. That won't work.
If you add the package statement and run "java
LearnJava.RichardFirstPackage.RichardFirstPackage", it will work. This is
the same thing that you're experiencing in NetBeans. Does that clear it up?
If not I'll try to explain it a different way.
 
R

Richard Bell

Richard Bell said:
*fix top post*
On Sun, 15 Feb 2004 21:00:56 -0600, "Ryan Stewart"


I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That
goes
for subdirectories of the mounted directories. They are considered
packages
and must be imported.


Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.


What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?

Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.
If you're working in NetBeans, you have a directory mounted. In the left
hand pane (Explorer), click the "Filesystems" tab at the bottom. This will
show you all mounted directories. You can mount a new one by right clicking
on the "Filesystem" thing at the top of the list/tree. From what you've
said, I would guess that you have "My Documents" mounted. That means that
your "My Documents" folder is in your classpath when you execute something.
The LearnJava and RichardFirstPackage folders are not. Anything in a
subdirectory of My Documents is considered by Java to be in a package and
*must* include a package statement. What you're doing is basically like
trying to run "java RichardFirstPackage" from My Documents. That won't work.
If you add the package statement and run "java
LearnJava.RichardFirstPackage.RichardFirstPackage", it will work. This is
the same thing that you're experiencing in NetBeans. Does that clear it up?
If not I'll try to explain it a different way.
Ryan,

Thanks for your patience. I'm still not entirely clear. When I
examine NetBeans "filesystems" tab I find a bunch of things listed
including

cd to C:\Documents and Settings\rbell\My Documents

Under which I can see all the files and directories in this directory.

I now have the Java code looking like this:

package LearnJava.RichardFirstPackage;

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

In NetBeans it executes as expected.

When I open a command window and

cd to C:\Documents and Settings\rbell\My
Documents\LearnJava\RichardFirstPackage>

then execute the command

java LearnJava.RichardFirstPackage.RichardFirstPackage

I get the error message

Exception in thread "main" java.lang.NoClassDefFoundError:
LearnJava/RichardFirstPackage/RichardFirstPackage

So that's a different set of messages than earlier but still NetBeans
and Java are behaving differently.

BTW, I've got classpath set to .;the directory the java sdk is
installed in. Do I have an issue with the classpath in NetBeans (I
think I read somewhere that NetBeans ignores classpath)?

Thanks for your patience and help.
 
R

Richard Bell

Richard Bell said:
*fix top post*
On Sun, 15 Feb 2004 21:00:56 -0600, "Ryan Stewart"


I've just downloaded NetBeans and am encountering errors when I try to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That
goes
for subdirectories of the mounted directories. They are considered
packages
and must be imported.


Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.


What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?

Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.
If you're working in NetBeans, you have a directory mounted. In the left
hand pane (Explorer), click the "Filesystems" tab at the bottom. This will
show you all mounted directories. You can mount a new one by right clicking
on the "Filesystem" thing at the top of the list/tree. From what you've
said, I would guess that you have "My Documents" mounted. That means that
your "My Documents" folder is in your classpath when you execute something.
The LearnJava and RichardFirstPackage folders are not. Anything in a
subdirectory of My Documents is considered by Java to be in a package and
*must* include a package statement. What you're doing is basically like
trying to run "java RichardFirstPackage" from My Documents. That won't work.
If you add the package statement and run "java
LearnJava.RichardFirstPackage.RichardFirstPackage", it will work. This is
the same thing that you're experiencing in NetBeans. Does that clear it up?
If not I'll try to explain it a different way.

Ryan,

I experimented a bit more and deleted a bunch of mounted file systems
then mounted the directory containing RichardFirstPackage.java.
Commented out the Package statement in the source. Lo and behold both
NetBeans and Java behave the same. Clearly, I'm new to this all, but
it appears that NetBeans was acting on one of the mounted file systems
before it got to the one referencing RichardFirstPackage.

A bit of searching in the help file reveals that NetBeans relies on
the mounted filesystems not the environmental variable classpath.
That explains the differences in behavior. Thanks for your patience
and help.
 
R

Ryan Stewart

Richard Bell said:
Richard Bell said:
On Mon, 16 Feb 2004 14:18:33 -0600, "Ryan Stewart"

*fix top post*
On Sun, 15 Feb 2004 21:00:56 -0600, "Ryan Stewart"


I've just downloaded NetBeans and am encountering errors when I
try
to
compile and execute classes that compiled and executed properly under
the SDK (1.4.2). In NetBeans I get a series of errors something like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at
java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java. That
goes
for subdirectories of the mounted directories. They are considered
packages
and must be imported.


Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.


What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?


Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.
If you're working in NetBeans, you have a directory mounted. In the left
hand pane (Explorer), click the "Filesystems" tab at the bottom. This will
show you all mounted directories. You can mount a new one by right clicking
on the "Filesystem" thing at the top of the list/tree. From what you've
said, I would guess that you have "My Documents" mounted. That means that
your "My Documents" folder is in your classpath when you execute something.
The LearnJava and RichardFirstPackage folders are not. Anything in a
subdirectory of My Documents is considered by Java to be in a package and
*must* include a package statement. What you're doing is basically like
trying to run "java RichardFirstPackage" from My Documents. That won't work.
If you add the package statement and run "java
LearnJava.RichardFirstPackage.RichardFirstPackage", it will work. This is
the same thing that you're experiencing in NetBeans. Does that clear it up?
If not I'll try to explain it a different way.

Ryan,

I experimented a bit more and deleted a bunch of mounted file systems
then mounted the directory containing RichardFirstPackage.java.
Commented out the Package statement in the source. Lo and behold both
NetBeans and Java behave the same. Clearly, I'm new to this all, but
it appears that NetBeans was acting on one of the mounted file systems
before it got to the one referencing RichardFirstPackage.

A bit of searching in the help file reveals that NetBeans relies on
the mounted filesystems not the environmental variable classpath.
That explains the differences in behavior. Thanks for your patience
and help.
No problem. I'm glad you figured it out. This is what I was trying to
explain earlier. The way you had it set up in NetBeans, with "My Documents"
mounted, was like trying to run "java RichardFirstPackage" from that same
directory because of the mounting/classpath thing. Obviously that class file
is not in that directory. You either have to mount the directory where your
file is, making it 1) a top-level file and 2) in the (NetBeans) classpath,
or you have to declare it to be part of a package and access it with a full
path (LearnJava.RichardFirstPackage.RichardFirstPackage). What you were
perceiving as the command line and NetBeans acting differently was actually
the two acting the same, but the classpath issue is what makes it confusing,
especially since you have "." in your classpath. That means anywhere you try
to run a class from the command line, it will work. NetBeans, as you saw, is
less forgiving. But still, in the end it's not NetBeans, it's Java. Give it
time. You'll get used to it.
 
R

Richard Bell

Richard Bell said:
On Mon, 16 Feb 2004 14:18:33 -0600, "Ryan Stewart"

*fix top post*
On Sun, 15 Feb 2004 21:00:56 -0600, "Ryan Stewart"


I've just downloaded NetBeans and am encountering errors when I try
to
compile and execute classes that compiled and executed properly
under
the SDK (1.4.2). In NetBeans I get a series of errors something
like
this:

java.lang.NoClassDefFoundError: LearnJava/VolcanoRobot/VolcanoRobot
(wrong name: VolcanoRobot)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at

java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at
java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native
Method)
at
java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

If I put the statement

package LearnJava.VolcanoRobot;

at the top of the file, all is well with NetBeans. Unfortunately
then
the SDK java command gives lots of errors, like this

Exception in thread "main" java.lang.NoClassDefFoundError:
VolcanoRobot (wrong name: LearnJava/VolcanoRobot/VolcanoRobot
)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown
Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native
Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I'm fairly usre I'm doing something really simple wrong (bad
configuration of some sort), but could use a clue.

Thanks

Realize that Netbeans adds mounted directories to the classpath. If
something isn't in a mounted directory, it is not visible to Java.
That
goes
for subdirectories of the mounted directories. They are considered
packages
and must be imported.


Ryan,

I'm not sure I understand what you've said. I've got a trivial
program like this:

public class RichardFirstPackage {

/** Creates a new instance of RichardFirstPackage */
public RichardFirstPackage() {
}

public static void main(String[] args) {
String user = System.getProperty("user.name");
System.out.println("xxx " + user);
}

}

When I compile with Javac (Classpath = .;c:\j2sdk1.4.2_03\lib and
Javac et al in the Path system variable) all is well and I can execute
with Java RichardFirstPackage.

If I now use NetBeans to compile and run this program I get the errors
previously indicated. Adding

package LearnJava.RichardFirstPackage;

before the class definition fixes all and I can run in Netbeans.
Unfortunately when I now try to compile in a command window with Javac
I get the second set of errors.

Is there something I need to set either in Netbeans or in XP to
arrange things such that I can interchangeable use both tools?

Thanks.


What directory do you have mounted in NetBeans? What directory is the
file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?


Ryan,

As far as I know I've no directories mounted in NetBeans.

RichardFirstPackage.class is in c:\Documents and Settings\rbell\My
Documents\LearnJava\RIchardFirstPackage

At command line, I'm running Javac and Java in that same directory.

It's not so much the problem that has me concerned as the
inconsistency between NetBeans and command line. I've got to believe
I'm doing something really foolish.

If you're working in NetBeans, you have a directory mounted. In the left
hand pane (Explorer), click the "Filesystems" tab at the bottom. This will
show you all mounted directories. You can mount a new one by right clicking
on the "Filesystem" thing at the top of the list/tree. From what you've
said, I would guess that you have "My Documents" mounted. That means that
your "My Documents" folder is in your classpath when you execute something.
The LearnJava and RichardFirstPackage folders are not. Anything in a
subdirectory of My Documents is considered by Java to be in a package and
*must* include a package statement. What you're doing is basically like
trying to run "java RichardFirstPackage" from My Documents. That won't work.
If you add the package statement and run "java
LearnJava.RichardFirstPackage.RichardFirstPackage", it will work. This is
the same thing that you're experiencing in NetBeans. Does that clear it up?
If not I'll try to explain it a different way.

Ryan,

I experimented a bit more and deleted a bunch of mounted file systems
then mounted the directory containing RichardFirstPackage.java.
Commented out the Package statement in the source. Lo and behold both
NetBeans and Java behave the same. Clearly, I'm new to this all, but
it appears that NetBeans was acting on one of the mounted file systems
before it got to the one referencing RichardFirstPackage.

A bit of searching in the help file reveals that NetBeans relies on
the mounted filesystems not the environmental variable classpath.
That explains the differences in behavior. Thanks for your patience
and help.
No problem. I'm glad you figured it out. This is what I was trying to
explain earlier. The way you had it set up in NetBeans, with "My Documents"
mounted, was like trying to run "java RichardFirstPackage" from that same
directory because of the mounting/classpath thing. Obviously that class file
is not in that directory. You either have to mount the directory where your
file is, making it 1) a top-level file and 2) in the (NetBeans) classpath,
or you have to declare it to be part of a package and access it with a full
path (LearnJava.RichardFirstPackage.RichardFirstPackage). What you were
perceiving as the command line and NetBeans acting differently was actually
the two acting the same, but the classpath issue is what makes it confusing,
especially since you have "." in your classpath. That means anywhere you try
to run a class from the command line, it will work. NetBeans, as you saw, is
less forgiving. But still, in the end it's not NetBeans, it's Java. Give it
time. You'll get used to it.
There may be just a bit more to it than that. As it happened, at one
point, I'm not sure when, but it was after I wrote the test program, I
had mounted RichardFirstPackage in NetBeans. That mount was way down
the list. NetBeans says it adds all the mounts to its Classpath.
Somewhere in the many mounts there was something (I never checked what
it was) that allowed NetBeans to work but only with the package
statement included. It seems that it is an order thing of some sort.
When I cleaned out all the mounts and started again as you suggested
all was well. Just a dumb new user error.

Thanks again for all your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top