1

This Question should not be closed as suggested answer does not answer question in this case.

The below code causes this error :

Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at scala.java.mixed.test.Driver.main(Driver.java:17)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 13 more

The code :

package parallel

import com.recommendations.EucleudianProperties

class TestData(var distanceMap : java.util.Map[java.lang.String , java.lang.String]) {

  object ProcessData{
    def apply {
      println("in apply method "+distanceMap.size)
    }
  }

}


package scala.java.mixed.test;

import java.util.HashMap;
import java.util.Map;
import parallel.TestData;

public class Driver {

    public static void main(String args[]){

        Map<String , String> distanceMap = new HashMap<String , String>();

        new TestData(distanceMap);
    }

}

What is causing this error ? Am I calling the Scala class TestData from java class Driver correctly ?

EDIT : here is the build path

enter image description here

4

1 回答 1

0

对我来说,问题是 scala-library.jar 没有在 Eclipse 运行配置中的类路径上配置,一旦我添加了它,它就会按预期运行。这是我更新的类路径:

在此处输入图像描述

于 2013-04-23T13:51:33.487 回答