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错误提示消失。