Job aborted due to stage failure: Task 2 in stage 9.0 failed 1 times: java.lang.NullPointerException

StrucetStream 读取kafka数据到mysql 里面报的错

Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 2 in stage 9.0 failed 1 times, most recent failure: Lost task 2.0 in stage 9.0 (TID 810, localhost, executor driver): java.lang.NullPointerException
	at com.czxy.Struct2_hw20200416.structStreaming_kafka_mysql$intoMysql.process(structStreaming_kafka_mysql.scala:73)
	at com.czxy.Struct2_hw20200416.structStreaming_kafka_mysql$intoMysql.process(structStreaming_kafka_mysql.scala:47)
	at org.apache.spark.sql.execution.streaming.ForeachSink$$anonfun$addBatch$1.apply(ForeachSink.scala:53)
	at org.apache.spark.sql.execution.streaming.ForeachSink$$anonfun$addBatch$1.apply(ForeachSink.scala:49)
	at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926)
	at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926)
	at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:2062)
	at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:2062)
	at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
	at org.apache.spark.scheduler.Task.run(Task.scala:108)
	at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:335)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

异常

Job aborted due to stage failure: Task 2 in stage 9.0 failed 1 times: java.lang.NullPointerException_第1张图片

解决措施

Job aborted due to stage failure: Task 2 in stage 9.0 failed 1 times: java.lang.NullPointerException_第2张图片

原因

因为定义了两个变量,全局的那个connections 没有链接上,所以程序走到下面时就会出现为空,所以把val 去掉,那个全局的connections 就有值了

你可能感兴趣的:(Job aborted due to stage failure: Task 2 in stage 9.0 failed 1 times: java.lang.NullPointerException)