在这种情况下,不应关闭此问题,因为建议的答案不能回答问题。

以下代码导致此错误:

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


代码 :

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);
    }

}


是什么导致此错误?我可以从Java类驱动程序正确调用Scala类TestData吗?

编辑:这是构建路径

最佳答案

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

10-06 06:23