Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

runtime problem

SweetPSweetP Posts: 35Member
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.28webappsegjsp-ch08WEB-INFclassescomwroxutilities>
java helloWorld
Hello World!

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

PROGRAM-2:

C:jakarta-tomcat-5.0.28webappsegjsp-ch08WEB-INFclassescomwroxutilities>
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.28webappsegjsp-ch08WEB-INFclassescomwroxutilities>
dir
Volume in drive C has no label.
Volume Serial Number is 8430-CDAB

Directory of C:jakarta-tomcat-5.0.28webappsegjsp-ch08WEB-INFclassescomw
roxutilities

03/15/2005 04:01 AM
    .
    03/15/2005 04:01 AM
      ..
      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
Sign In or Register to comment.