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
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