Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,

I am New to Big Data World.need urs help to make it real.here is myquestion
I am Reading data from txt file(1,2,3,4,4,4,4)

var file=sc.textFile("file:///home/cloudera/MyData/Lab1/numbers.txt")
var number=file.flatMap(line=>line.split(","))
var intNumbers=number.map(num=>num.toInt)//Error
intNumbers.collect()
java.lang.NumberFormatException: For input string: ""

error is coming due to last element of array not able to convert to Int

PLease help on that
Thanks In Advance.


Regards,
Learning Spark

What I have tried:

added data in file like (1,2,3,4,4,4,4,)
but still shows same error
Array[String] = Array(1,2,3,4,5,6,4,4,4,4,, "")
Posted
Updated 16-Jun-18 21:54pm

1 solution

The data contains an item that is not a number, so you need to strip that out of your list before trying to convert.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900