IntelliJ错误:发生JNI错误,请检查您的安装并重试

时间:2017-03-26 20:32:55

标签: intellij-idea

我正在尝试在intellij中运行一个项目,每次运行特定的类时,都会收到以下错误消息:

*Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/StreamingContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.streaming.StreamingContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)**

2 个答案:

答案 0 :(得分:0)

您必须使用spark版本将spark-streaming依赖项添加到SBT中:

libraryDependencies + =“ org.apache.spark” %%“ spark-streaming”%“您的Spark版本”

答案 1 :(得分:0)

很长时间以来,我都面临着相同的问题,我的代码在执行以下行时引发了相同的错误:

val ssc = new StreamingContext(sc, Seconds(10))

我的POM.xml看起来像这样:

<dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.11</artifactId>
      <version>2.3.4</version>
      <scope>provided</scope>
</dependency>

您看到另外的行<scope>吗?一旦我从POM文件中删除了该行,代码便回到了正确的轨道,并成功执行了。

因此,请确保从<scope>中删除dependency

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming_2.11</artifactId>
        <version>2.3.4</version>
    </dependency>