Computer Science Canada

I'm stumped

Author:  wtd [ Thu Nov 17, 2005 5:54 pm ]
Post subject:  I'm stumped

My program compiles fine, but I get:

code:
Exception in thread "main" java.lang.NoClassDefFoundError: Test


When I run it, and I can't see any of the usual causes of this problem.

Java:
public class Test {
   public static void main(String[] args) {
      String[] testArray = {"hello", " ", "world"};

      System.out.println(concat(testArray));
   }

   static String concat(String[] arr) {
          return Fold.foldLeft(arr, "", new Function<String, String>() {
             public String apply(String a, String b) {
                return a + b;
             }
      });
   }
}

interface Function<I, O> {
   public O apply(O a, I b);
}

class Fold {
   public static <I, O> O foldLeft(I[] arr, O initialValue, Function<I, O> func) {
      for (I x : arr)
         initialValue = func.apply(initialValue, x);

      return initialValue;
   }
}

Author:  beard0 [ Thu Nov 17, 2005 10:30 pm ]
Post subject: 

Err... compiles and runs fine for me. jdk1.5.0_05 & jre1.5.0_05

Author:  MysticVegeta [ Thu Nov 17, 2005 10:46 pm ]
Post subject: 

oh I get the same error, maybe I need to upgrade mine to jdk1.5

Author:  wtd [ Thu Nov 17, 2005 10:47 pm ]
Post subject: 

beard0 wrote:
Err... compiles and runs fine for me. jdk1.5.0_05 & jre1.5.0_05


Same here.

Author:  Hikaru79 [ Thu Nov 17, 2005 11:25 pm ]
Post subject: 

Works fine here. If you're doing this in Windows, make sure you run it with
code:
java -cp . Test
. The current directory isn't in the classpath by default. You can also set an environment variable to fix this if you don't want to set it every time.

Author:  wtd [ Thu Nov 17, 2005 11:32 pm ]
Post subject: 

Hikaru79 wrote:
Works fine here. If you're doing this in Windows, make sure you run it with
code:
java -cp . Test
. The current directory isn't in the classpath by default. You can also set an environment variable to fix this if you don't want to set it every time.


Excellent.


: