Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NetBeans v. SDK

1 view
Skip to first unread message

Richard Bell

unread,
Feb 15, 2004, 5:46:24 PM2/15/04
to

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

Ryan Stewart

unread,
Feb 15, 2004, 10:00:56 PM2/15/04
to
"Richard Bell" <rbell...@earthlink.net> wrote in message
news:8atv20laobrkuqnc6...@4ax.com...

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.


Richard Bell

unread,
Feb 16, 2004, 2:24:50 PM2/16/04
to

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.

Ryan Stewart

unread,
Feb 16, 2004, 3:18:33 PM2/16/04
to
"Richard Bell" <rbell...@earthlink.net> wrote in message
news:tr5230lih0bou2b3t...@4ax.com...
*fix top post*
What directory do you have mounted in NetBeans? What directory is the file
RichardFirstPackage.class in? What directory are you running java
RichardFirstPackage from?


Richard Bell

unread,
Feb 16, 2004, 7:12:34 PM2/16/04
to
On Mon, 16 Feb 2004 14:18:33 -0600, "Ryan Stewart"
<zzanN...@gSPAMo.com> wrote:

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.


Ryan Stewart

unread,
Feb 16, 2004, 8:03:29 PM2/16/04
to
"Richard Bell" <rbell...@earthlink.net> wrote in message
news:9sm2309oag7q07d0j...@4ax.com...
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.


Richard Bell

unread,
Feb 17, 2004, 6:36:59 PM2/17/04
to
On Mon, 16 Feb 2004 19:03:29 -0600, "Ryan Stewart"
<zzanN...@gSPAMo.com> wrote:

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.


Richard Bell

unread,
Feb 17, 2004, 6:48:00 PM2/17/04
to
On Mon, 16 Feb 2004 19:03:29 -0600, "Ryan Stewart"
<zzanN...@gSPAMo.com> wrote:

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.


Ryan Stewart

unread,
Feb 17, 2004, 7:45:26 PM2/17/04
to
"Richard Bell" <rbell...@earthlink.net> wrote in message
news:1s95301iati4gbge6...@4ax.com...
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.


Richard Bell

unread,
Feb 18, 2004, 8:51:33 PM2/18/04
to
On Tue, 17 Feb 2004 18:45:26 -0600, "Ryan Stewart"
<zzanN...@gSPAMo.com> wrote:

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.

0 new messages