IDEA版本为2016.3
书写为简单的Spark WordCount代码
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
/**
* Created by Joe on 2017/4/20.
*/
public class WordCount {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setMaster("local").setAppName("wordcount");
JavaSparkContext context = new JavaSparkContext(conf);
JavaRDD<String> lineRdd = context.textFile("C:\\spark-2.1.0-bin-hadoop2.6\\README.md");
lineRdd.foreach(line -> System.out.println(line));
JavaRDD<String> words = lineRdd.map(line -> {
String[] speces = line.split(" ");
return speces[0];
});
words.foreach(line -> System.out.println(line));
}
}
但是在IDEA里面会有代码提示报错
但是在程序编译的时候是没有问题的。代码可以正常运行。
代码是正常退出的。
其中的Pom文件为
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.learn</groupId>
<artifactId>spark_maven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<!-- Change the nd4j.backend property to nd4j-cuda-7.5-platform or nd4j-cuda-8.0-platform to use CUDA GPUs -->
<nd4j.backend>nd4j-native-platform</nd4j.backend>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<shadedClassifier>bin</shadedClassifier>
<spark.version>2.1.0</spark.version>
<scala.version>2.11.8</scala.version>
<jedis.version>2.8.2</jedis.version>
<fastjson.version>1.2.14</fastjson.version>
<jetty.version>9.2.5.v20141112</jetty.version>
<container.version>2.17</container.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.10</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${container.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${container.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>${container.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${container.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-actors</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_2.11</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_2.11</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scalap</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerId>eclipse</compilerId>
</configuration>
</plugin>
</plugins>
</build>
</project>
请教如何使得IDEA不进行这个代码错误提示。
mvnidea:idea试试
mvnidea:idea试试
incompatibleequalityconstraint
这种报错应该如何解决
编译级别的问题吧,lambda表达式只有JDK8才支持
...............运行无错。只是提示报错IDEA卸载之后重新安装2016.3.2就没有问题了
同样的问题,路过
你尝试一下把右下角的报错级别更改一下
我之前也碰到有报错但不影响然后就是调报错级别后红线就没了并不是这个问题。那个问题的出现就是语法问题。我前面也说错是卸载重新安装解决得。。
不知道楼主问题解决没有?我今天也遇到了同样的问题,供参考:
我的情况是新安装了一个程序,其自动重新安装了我的jdk(连版本都没变)。此后状况和楼主一样,intellij无论打开哪个项目,代码一概报错,犹如没有配置项目sdk一样。但检查各种设置完全无误,程序也能运行。期间更新了intellij版本,也无影响。
解决方案是在File菜单中点击InvalidateCachesandRestart。重启intellij之后问题解决。(参考了http://cwind.iteye.com/blog/2364052)
猜想这个问题是因为intellij的代码查错会利用缓存,而本地jdk更改后缓存里没有更新;至于编译运行为了保证每次都独立所以不过缓存,因此没有问题。intellij的缓存默认不随退出而清空,所以重启、更新都无效。但如上面所说,卸载重安大概也能解决问题。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。