runtime problem

P

pete

I am having a problem running a program called ArrayListDemo.... I
believe the JRE is able to find the programs within this directory,
because I am able to run my helloWorld program without any problems....

Here's some output:

#############################

PROGRAM-1:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilities>
java helloWorld
Hello World!

#############################

PROGRAM-2:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilities>
java ArrayListDemo
Exception in thread "main" java.lang.NoClassDefFoundError:
ArrayListDemo (wrong
name: com/wrox/utilities/ArrayListDemo)
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)

#############################

DIRECTORY-STRUCTURE:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilities>
dir
Volume in drive C has no label.
Volume Serial Number is 8430-CDAB

Directory of
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\w
rox\utilities

03/15/2005 04:01 AM <DIR> .
03/15/2005 04:01 AM <DIR> ..
03/15/2005 04:00 AM 1,312 ArrayListDemo.class
03/15/2005 03:58 AM 883 ArrayListDemo.java
02/27/2005 02:16 AM 426 helloWorld.class
03/15/2005 04:00 AM 681 User.class
03/30/2005 02:51 AM 442 User.java
5 File(s) 3,744 bytes
2 Dir(s) 25,463,304,192 bytes free

#############################

Obviously, my problem is with Program-2... I checked my file name and
class name and they match, plus I was able to run the helloWorld
program within the same directory as the ArrayListDemo program, which
doesn't run, as illustrated above..... Can someone tell me why the 2nd
program will not run, based on the foregoing information??? Also
here's the code for both of the relative files:

#############################

package com.wrox.utilities;
import java.util.ArrayList;
//import java.util.*;

public class ArrayListDemo{
public static void main(String[] args){
User usr1 = new User("J Smith","123-444-4444");
User usr2 = new User("M Walkder","123-555-5555");
User usr3 = new User("R Johnson","123-666-6666");

ArrayList userlist = new ArrayList();
userlist.add(usr3);
userlist.add(usr1);
userlist.add(usr2);

User usr = (User) userlist.get(1);
System.out.println("Second user...");
System.out.println("Username: " + usr.getUsername());
System.out.println("User phone number: " + usr.getPhoneNumber());
System.out.println("Userlist...");

for(int i=0; i<userlist.size(); i++){
usr = (User) userlist.get(i);
System.out.println("Username: " + usr.getUsername());
System.out.println("User phone number: " + usr.getPhoneNumber());
}
}
}

#############################

package com.wrox.utilities;

public class User{
String username;
String phonenumber;

public User(){}

public User(String uname, String pnum){
username=uname;
phonenumber=pnum;
}

void setUsername(String uname){
this.username=uname;
}

String getUsername(){
return username;
}

void setPhonenumber(String pnum){
this.phonenumber=pnum;
}

String getPhoneNumber(){
return phonenumber;
}
}

#############################

Please note, that both of these files do compile without any
problems......... The first runs and the second doesn't?!?!?!

Any help will be much appreciated....

Thanks!

Pete
 
W

Wendy Smoak

I am having a problem running a program called ArrayListDemo.... I
believe the JRE is able to find the programs within this directory,
because I am able to run my helloWorld program without any problems....
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilit
ies>
java helloWorld
Hello World!
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilit
ies>
java ArrayListDemo
Exception in thread "main" java.lang.NoClassDefFoundError:
ArrayListDemo (wrong
name: com/wrox/utilities/ArrayListDemo)

Ignoring the fact that this looks like a web application directory
structure, the name of that class is com.wrox.utilities.ArrayListDemo, not
ArrayListDemo.

Put yourself in
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes

And then try:
java com.wrox.utilities.ArrayListDemo

Look at the errata for page 179 and see if it applies to you:
http://support.apress.com/errata/1861002092_errata.htm

If that doesn't work, ArrayListDemo is probably meant to be executed within
the web application. Try starting Tomcat and visiting
http://localhost:8080/begjsp-ch08
 
P

pete

Wendy/Anyone Else, your command worked..... Now I need to know why
mine didn't work and why your command did????

#############################

Good output:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes>java
com.wrox.utilities.ArrayListDemo
Second user...
Username: J Smith
User phone number: 123-444-4444
Userlist...
Username: R Johnson
User phone number: 123-666-6666
Username: J Smith
User phone number: 123-444-4444
Username: M Walkder
User phone number: 123-555-5555

#############################

Bad output:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes>java
com\wrox\utilities\ArrayListDemo
Exception in thread "main" java.lang.NoClassDefFoundError:
com\wrox\utilities\Ar
rayListDemo (wrong name: com/wrox/utilities/ArrayListDemo)
.....

#############################

I have read quite a bit on JAVA and never did I see any implication
that my filename in this case is com.wrox.utilities.ArrayListDemo,
opposed to ArrayListDemo, which is what I always knew it to be.....
From what I have learned my filename is ArrayListDemo, as listed in the
folder and in my class delcaration within the class.... And the 2
books that I have read are both by Wrox, Core JAVA and Beg Web Dev
w/JSP..... Where can I find comprehensive documentation on this topic,
because it is absolutely driving me nuts!!!!!!

Thanks again!

Pete
 
P

Pete

Wendy said:
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilit
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilit

Ignoring the fact that this looks like a web application directory
structure, the name of that class is
com.wrox.utilities.ArrayListDemo, not
ArrayListDemo.

Put yourself in
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes

And then try:
java com.wrox.utilities.ArrayListDemo

Look at the errata for page 179 and see if it applies to you:
http://support.apress.com/errata/1861002092_errata.htm

If that doesn't work, ArrayListDemo is probably meant to be executed within
the web application. Try starting Tomcat and visiting
http://localhost:8080/begjsp-ch08

Wendy, your command worked..... Now I need to know why mine didn't
work and why your command did????

#############################

Good output:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes>java
com.wrox.utilities.ArrayListDemo
Second user...
Username: J Smith
User phone number: 123-444-4444
Userlist...
Username: R Johnson
User phone number: 123-666-6666
Username: J Smith
User phone number: 123-444-4444
Username: M Walkder
User phone number: 123-555-5555

#############################

Bad output:

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch08\WEB-INF\classes>java
com\wrox\utilities\ArrayListDemo
Exception in thread "main" java.lang.NoClassDefFoundError:
com\wrox\utilities\Ar
rayListDemo (wrong name: com/wrox/utilities/ArrayListDemo)
.....

#############################

I have read quite a bit on JAVA and never did I see any implication
that my filename in this case is com.wrox.utilities.ArrayListDemo,
opposed to ArrayListDemo, which is what I always knew it to be.....
From what I have learned my filename is ArrayListDemo, as listed in the
folder and in my class delcaration within the class.... And the 2
books that I have read are both by Wrox, Core JAVA and Beg Web Dev
w/JSP..... Where can I find comprehensive documentation on this topic,
because it is absolutely driving me nuts!!!!!!

Thanks again!

Pete
 
H

Hikikomori

I am sure you must have come across the term "fully qualified class
name"? In Java, a class is identified by its fully qualified class
name. The fully
qualified class name consists of the package name and the class name.
In your case, com.wrox.utilities is the package name and ArrayListDemo
is the class name.
 
W

Wendy S

Pete said:
Wendy, your command worked..... Now I need to know why mine didn't
work and why your command did????

Read up on how the JVM uses the CLASSPATH to locate classes at runtime:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
http://mindprod.com/jgloss/classpath.html
(#9 is the situation you're in with ArrayListDemo. Note that if
you do NOT specify a classpath, then the default is "the current directory".
That's what you're using, and it's equivalent to "-classpath ." )

And I'm still not sure why they have you manually executing things that live
in a Tomcat webapp.
 

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

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,301
Latest member
BuyPureganics

Latest Threads

Top