美文网首页
Flink用scala写出现Type mismatch

Flink用scala写出现Type mismatch

作者: Jorvi | 来源:发表于2020-09-07 19:48 被阅读0次

1. 异常

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
import org.learn.source.SourceFromFile
import org.learn.vo.ClassInfo  

object WordCount {
  def main(args: Array[String]): Unit = {
    val streamEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    streamEnvironment
      .addSource(new SourceFromFile)
      .map(x => parseJson(x))

    streamEnvironment.execute()
  }
}

IDEA提示错误:

Type mismatch.
Required: MapFunction [String, NotInferedR]
Found:    Function1   [Nothing, ClassInfo]

2. 错误原因

StreamExecutionEnvironment导包错误。

用scala写时,应该导入:

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

导入新包后,IDEA错误提示消失。

相关文章

网友评论

      本文标题:Flink用scala写出现Type mismatch

      本文链接:https://www.haomeiwen.com/subject/gvgosktx.html