1. 程式人生 > >Flink中scala提示錯誤——could not find implicit value for evidence parameter of type org.apa

Flink中scala提示錯誤——could not find implicit value for evidence parameter of type org.apa

Flink第一個簡單的demo ,wordCount

該問題參考引用如下:

https://blog.csdn.net/dax1n/article/details/70211035


自身程式碼中問題:

package cetc.flink

import org.apache.flink.api.scala.ExecutionEnvironment

object FlinKMain {

  def main(args: Array[String]): Unit = {
    // 1.設定執行環境
    val env = ExecutionEnvironment.getExecutionEnvironment

    //2.創造測試資料
val text = env.fromElements("To be, or not to be,that is the question") //3.進行wordcount運算 val counts = text.flatMap(_.toLowerCase.split("\\W+")) .map((_, 1)).groupBy(0).sum(1) //4.列印測試結構 counts.print() } }

執行時候出錯如下:

Error:(13, 32) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
    val text = env.fromElements("To be, or not to be,that is the question")
Error:(13, 32) not enough arguments for method fromElements: (implicit evidence$14: scala.reflect.ClassTag[String], implicit evidence$15: org.apache.flink.api.common.typeinfo.TypeInformation[String])org.apache.flink.api.scala.DataSet[String].
Unspecified value parameter evidence$15.
    val text = env.fromElements("To be, or not to be,that is the question")

解決問題:

這是因為在當前環境之下找到不到scala的包,引入如下宣告即可

import org.apache.flink.api.scala._

產生這個問題的原因(官網說明):

1:A frequent reason if that the code that generates the TypeInformation has not been imported. Make sure to import the entire flink.api.scala package.

2:Another common cause are generic methods, which can be fixed as described in the following section.

我碰到的是問題1的情況。