0

Below is my code that returning NullPointer exception. but reading using fileReader it is returning value as expected.

var readChannel:ReadChannel  = storage.reader(blobId)
var excelFileRead:InputStream =  Channels.newInputStream(readChannel)
var br:BufferedReader = new BufferedReader(new InputStreamReader(excelFileRead))
var csvReader: CSVReader = new CSVReader(br)
csvReader.readNext
8
  • 1
    Please provide proper Java code, and also the complete stacktrace for the exception. (With the question in its current form, the best we can do is to close it as a dup of the canonical question on fixing NPEs.) Commented Feb 10, 2021 at 11:38
  • added the code please provide the solutions Commented Feb 12, 2021 at 8:40
  • I don't see the stacktrace ..... Commented Feb 12, 2021 at 9:42
  • Please find the stacke trace Commented Feb 15, 2021 at 6:14
  • 2021-02-15 11:42:35.958+0530 XAV-602000112 67128 [http-nio-8084-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/galileo/api/v1] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null at scala.collection.mutable.ArrayOps$ofRef$.length$extension(ArrayOps.scala:192) at scala.collection.mutable.ArrayOps$ofRef.length(ArrayOps.scala:192) at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:32) Commented Feb 15, 2021 at 6:16

1 Answer 1

1

Please find the beow code that is working fine for me:-Initially i was using CsvReader that was returning the null value but it is working fine with BufferReader as shown below.

  def getHeaderFromFile(blobId: BlobId,storage: Storage): Array[String] = {
   val readChannel:ReadChannel  = storage.reader(blobId)
   val excelFileRead:InputStream =  Channels.newInputStream(readChannel)
   val br:BufferedReader = new BufferedReader(new InputStreamReader(excelFileRead))
   val header:String = br.readLine()
   val headers: Array[String] = header.split(",")
    headers
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.