-4
19:45:37.624 [main] ERROR c.s.s.z.c.w.r.MP - Error while updating table:     MyFile, Error: java.lang.NullPointerException
java.lang.NullPointerException: null
    at java.util.Objects.requireNonNull(Unknown Source) ~[na:1.8.0_91]
    at java.util.Arrays$ArrayList.<init>(Unknown Source) ~[na:1.8.0_91]
    at java.util.Arrays.asList(Unknown Source) ~[na:1.8.0_91]
    at com.sl.sy.z.MU.getLM(MU.java:367) ~[classes/:na]
    at com.sl.sy.z.rr.MP.searchInP(MP.java:556) ~[classes/:na]
    at com.sl.sy.z.rr.MP.processR(MP.java:166) ~[classes/:na]
    at com.sl.sy.z.rr.RRMUpdate.processRR(RRMUpdate.java:139) [classes/:na]
    at com.sl.sy.z.RREReader.main(RREReader.java:101) [classes/:na]

Here is the error. Kindly Let me know why this error appears.

Saurabh
  • 62
  • 1
  • 15
  • 1
    http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it – Nicolas Filotto Jun 27 '16 at 16:11
  • 3
    With absolutely no code shown its hard to tell, but it looks like you're calling `Arrays.asList(null)` at `com.sl.sy.z.MU.getLM` (line 367 in MU.java) – Krease Jun 27 '16 at 16:12

2 Answers2

1

This code is safe:

List<?> list = Arrays.asList(null, null);

This code, however, which is what you appear to be doing, is not safe:

List<?> list = Arrays.asList(null);

The reason for this is that Arrays.asList is a varargs method. A sequence of varargs is simply an alternate notation for an array, so while the actual definition is asList(T... a), that definition is (nearly) equivalent to asList(T[] a). If you pass multiple arguments, or a single argument whose type is not Object, the compiler knows that no other method in the Arrays class can possibly match, so it knows to implicitly compose an array from those multiple arguments.

But a single null has no type, so it can only be inferred as Object. A null Object could be of any type, including an array. The compiler favors explicit code over automatically adjusted code and assumes you are trying to pass a null array, not a null that the compiler is supposed to intelligently compose into an array for the purpose of method invocation.

The simplest solution is to replace Arrays.asList(null) with Collections.singletonList(null).

VGR
  • 40,506
  • 4
  • 48
  • 63
0

Well thank you for the solution. But I have found the answer for the above question. In my case, it was related to the Excel sheet from where I am reading the data. The variable assigned to read the cell contents from the XML was not getting updated with the data because of the cell data doesn't containing value with a comma, whereas I was checking it under a condition that if the values contains comma ","

Saurabh
  • 62
  • 1
  • 15