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
38
votes
6 answers

findFragmentById return null

When I call findFragmentById() with the id of my fragment, it returns null. activity_main.xml
simperreault
  • 896
  • 1
  • 7
  • 17
38
votes
2 answers

Java code evaluation (IntelliJ IDE), use toString() in some point?

When evaluating object initialization, toString nullPointerException appear. Method threw 'java.lang.NullPointerException' exception. Cannot evaluate XXXX.toString() Code example which recreates this issue: Car car =…
Johnny
  • 14,397
  • 15
  • 77
  • 118
37
votes
6 answers

Google-guava checkNotNull and IntelliJ IDEA's "may produce java.lang.NullPointerException"

Is there any way to suppress this warning: MyClass object = null; /*Some code that 'might' set this object but I know it will*/ Preconditions.checkNotNull(object); //when "assert object != null" is used here no warning is…
Sebastian
  • 663
  • 1
  • 7
  • 20
37
votes
1 answer

NPE on Facebook SDK 4.10 : Attempt to invoke interface method 'java.lang.Object com.facebook.inject.Lazy.get()' on a null object reference

Background Recently we've updated the Facebook SDK library to 4.10 (from here). Before, we had the same bug now and then, but now it seems it occurs a lot more often. The problem There is no way for us to understand where and why it occurs. Here's…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
36
votes
4 answers

javax.xml.parsers.FactoryConfigurationError running JBoss AS 7.1 with Java 7 update 171

Upgrading Java from 7u161 to 7u171 prevents JBoss AS 7.1.1.Final from starting. I know JBoss AS 7.1.1 is EOL but for compatibility reasons, we still need to run this version. Very early in the startup, a NullPointerException occurs in some JBoss…
David Le Borgne
  • 801
  • 2
  • 9
  • 23
36
votes
5 answers

Java conditional operator ?: result type

I'm a bit puzzled about the conditional operator. Consider the following two lines: Float f1 = false? 1.0f: null; Float f2 = false? 1.0f: false? 1.0f: null; Why does f1 become null and the second statement throws a…
36
votes
4 answers

parseSdkContent failed Could not initialize class android.graphics.Typeface

When I open layout editor, eclipse is giving this error: parseSdkContent failed Could not initialize class android.graphics.Typeface And when I try to run project, it is giving this error : An internal error occurred during: "Launching…
Lazy
  • 1,807
  • 4
  • 29
  • 49
36
votes
15 answers

Null pointer error with hideSoftInputFromWindow

I get a null pointer exception at this row: public void hideKeyboard(){ InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); …
basickarl
  • 37,187
  • 64
  • 214
  • 335
36
votes
8 answers

printStackTrace to java.util.logging.Logger

How do I print the entire stack trace using java.util.Logger? (without annoying Netbeans). The question should've originally specified staying within Java SE. Omitting that requirment was an error on my part. -do-compile: [mkdir] Created dir:…
Thufir
  • 8,216
  • 28
  • 125
  • 273
35
votes
7 answers

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference

I have BitmapScalingHelper.java: public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds =…
35
votes
8 answers

Proper way to handle Android Studio's NullPointerException lint warning

I'm new to android/java programming and am confused how to properly deal with this warning. Method invocation '' may produce 'Java.lang.NullPointerException' Should I be ussing assert to remove the warning? Or rather a runtime exception? Any…
Hackmodford
  • 3,901
  • 4
  • 35
  • 78
34
votes
22 answers

Android SDK Content Loader failing with NullPointerException

I've just recently started getting an error any time I interact with the Android SDK and AVD Manager in Eclipse Helios I've tried reinstalling the Eclipse plugin and the Android SDK but to no avail. If I go to the "Installed packages" page and click…
Tim
  • 5,767
  • 9
  • 45
  • 60
34
votes
10 answers

java.lang.Class java.lang.Object.getClass()' on a null object reference

I try to use viewPager with the tablayout but when i set adapter with the view pager i'm getting error "java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass() on a null object reference" i don't…
xyz rety
  • 671
  • 2
  • 11
  • 22
34
votes
19 answers

Errors running builder 'Android Resource Manager' on ADT

I am facing a problem when I try to create new android project in eclipse adt plugin tools. ERROR/EXCEPTION:: Errors occurred during the build. Errors running builder 'Android Resource Manager' on project 'test'. java.lang.NullPointerException I…
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
34
votes
9 answers

NullPointerException when Creating an Array of objects

I have been trying to create an array of a class containing two values, but when I try to apply a value to the array I get a NullPointerException. public class ResultList { public String name; public Object value; } public class Test { …
marjasin
  • 351
  • 1
  • 3
  • 4