Questions tagged [nullpointerexception]

The Java exception thrown when an application attempts to use null in a case where an object is required.

This Java is thrown when an application attempts to use null in a case where an object is required.

These include:

  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.
  • Unboxing of null object.

Applications should throw instances of this exception to indicate other illegal uses of the null object.

It's often abbreviated as NPE

Practically all questions with this tag are duplicates of the canonical What is a NullPointerException and how do I fix it?.

15961 questions
33
votes
4 answers

Android, How to use readTypedList method correctly in a Parcelable class?

I have two Activities, in the first one, I instanciate an ArrayList of Object myObject. In the second activity, i need to get this Arraylist. I've found a tutorial : http://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.html I have…
Gen
  • 403
  • 2
  • 6
  • 9
32
votes
2 answers

Why Kotlin data classes can have nulls in non-nullable fields with Gson?

In Kotlin you can create a data class: data class CountriesResponse( val count: Int, val countries: List, val error: String) Then you can use it to parse a JSON, for instance, "{n: 10}". In this case you will have an object val…
CoolMind
  • 26,736
  • 15
  • 188
  • 224
31
votes
3 answers

- java.lang.NullPointerException - setText on null object reference

This is what I'm trying to do for several hours: I've got a MainActivity.java file (listing below) and a fragment_start.xml file with a start button. Tapping the start-button should display the activity_main.xml file with points-/round- and…
George
  • 367
  • 1
  • 3
  • 4
30
votes
12 answers

Possible reason for "Error:cannot generate view binders java.lang.NullPointerException"

I am using Android Studio for my Android projects. I faced an issue when builds crash with strange stacktrace, like this: Error:Execution failed for task ':app:compileDevDebugJavaWithJavac'. java.lang.RuntimeException: failure, see logs for…
30
votes
4 answers

Attempt to invoke virtual method 'int android.text.Layout.getLineCount()' on a null object reference

I am getting null pointer exception randomly, usually it works and sometime it crashes, I had searched a lot but didn't get any help as it there is no proper line from where I get any help, I am also using handler with it. My logcat error is as…
Reprator
  • 2,859
  • 2
  • 32
  • 55
30
votes
3 answers

NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference

I am getting this error at runtime. java.lang.RuntimeException: Unable to start activity ComponentInfo java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null…
Steve
  • 1,153
  • 2
  • 15
  • 29
30
votes
8 answers

Find out what variable is throwing a NullPointerException programmatically

I know I can find out if a variable is null in Java using these techniques: if (var==null) -> too much work try { ... } catch (NullPointerException e) { ...} -> it tells me what line is throwing the exception using the debugger -> by hand, too…
Hectoret
  • 3,553
  • 13
  • 49
  • 56
29
votes
2 answers

How do I get @ParametersAreNonnullByDefault to work?

I've made several attempts at getting package annotation @ParametersAreNonnullByDefault to work for me in a maven project but with no success. Could someone share a link to a minimal/sample maven project where this is setup (or post the pom.xml and…
simpatico
  • 10,709
  • 20
  • 81
  • 126
29
votes
4 answers

Is None less evil than null?

In F# its a big deal that they do not have null values and do not want to support it. Still the programmer has to make cases for None similar to C# programmers having to check != null. Is None really less evil than null?
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
29
votes
9 answers

Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference

My Application consist of 4 fragment as tabs being loaded inside a parent Fragment using FragmentPagerAdapter. The problem is when I run the app and press back and re-open the app I receive this error log: FATAL EXCEPTION:…
29
votes
9 answers

JPA/Hibernate Static Metamodel Attributes not Populated -- NullPointerException

I would like to use JPA2 Criteria API with metamodel objects, which seems to be pretty easy: ... Root albm = cq.from(JPAAlbum.class); ... albm.get(JPAAlbum_.theme) ... ; but this Root.get always throws a NullPointerException.…
Kevin
  • 4,618
  • 3
  • 38
  • 61
29
votes
5 answers

Eclipse debugging has dialog box: Exception processing async thread queue java.lang.NullPointerException

I am facing a problem while debugging in Eclipse 3.4.2. I keep getting pop-up Exception processing async thread queue java.lang.NullPointerException Does anyone know what the exact problem is? Thanks
yogsma
  • 10,142
  • 31
  • 97
  • 154
29
votes
7 answers

Is there a C++ equivalent of a NullPointerException

Both Java and C#, and probably many other languages too, have a predefined exception class that is thrown when a null parameter is used where it should not. Is there anything similar in C++? If not, is there another predefined exception I can use or…
Janina Petersen
  • 293
  • 1
  • 3
  • 5
29
votes
7 answers

Why doesn't Java tell you which pointer is null?

I've always wondered why the JVM doesn't tell you which pointer (or more precisely, which variable) is null when a NullPointerException is thrown. A line number isn't specific enough because the offending line can often contain numerous variables…
kpozin
  • 25,691
  • 19
  • 57
  • 76
28
votes
1 answer

NPE on com.android.server.autofill.RemoteFillService$PendingRequest.cancel()

Crashlytics is reporting NullPointerException related to Auto Fill as shown below: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.server.autofill.RemoteFillService$PendingRequest.cancel()' on a…
Sanjay Kumar
  • 1,135
  • 14
  • 27