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

How to catch the exception caused by an absence of an object in Java?

I have a very simple method: public int getScore() { return game.gameWindow.userBestScore; } The problem is that it can happens that game object or gameWindow do not exist. I do not want to get the Null Pointer Exception. How can catch it in a…
Roman
  • 124,451
  • 167
  • 349
  • 456
2
votes
1 answer

NullPointerException in ListView

Hy!! I have a listview that should be filled with data from the database Code: private void onCreateDBAndDBTabled() { myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null); myDB.execSQL("CREATE TABLE IF NOT EXISTS " +…
test123123
  • 911
  • 3
  • 16
  • 33
2
votes
0 answers

the flutter app does not launch FacebookRequestErrorClassification null pointer exception

i'm getting this error in the launch of the flutter app, in both release & debug mode. this started without changing anything. flutter doctor seems good Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int…
2
votes
0 answers

SWT GTK 64 bit and UBUNTU 11.04 NPE

I'm currently working in an SWT standalone application. We usually work with windows but I'd like to work in Ubuntu.I set up the following environment. Ubuntu 11.04 64bit Java 6 update 27 64 bit Eclipse Java EE 3.5 Galileo 64 bit I'm using SWT GTK…
rodrigogp
  • 66
  • 1
  • 5
2
votes
4 answers

Clojure NullPointerException error

I'm new in clojure and try to write simple function which get list of numbers and filter only even numbers. I want to do it witout filter or even?, only pure clojure (defn my-even [ilist] (if (= (mod (first ilist) 2) 0) (concat (list…
0xAX
  • 20,957
  • 26
  • 117
  • 206
2
votes
1 answer

Enabled accessibility in combination with Jetpack Compose and AndroidView leads to an NullPointerException in onInitializeAccessibilityNodeInfo

At the moment I see a lot of NullpointerExceptions in FirebaseCrashlytics. The NPE occurs in this line of AndroidComposeView.kt. The problem is probably caused by TalkBack in combination with the AndroidView, but I can't reproduce it locally. It is…
user1185087
  • 4,468
  • 1
  • 30
  • 38
2
votes
3 answers

Trying to set up OAuth with Ktor, providerLookup problems

So Im trying to set up OAuth for Kotlin, Ktor. Im trying to follow the documentation on but I get stuck on the config part on step 2. When my program runs: call.request.queryParameters["redirectUrl"]!! I get a null point exeption. When running the…
Fprogramer
  • 63
  • 7
2
votes
3 answers

explanation needed: ternary operator in java

The line in question is return pFile.exists() ? true : null;. As it does not raise any compilation error, what is the explanation for this. It ended up raising NPE. import java.io.File; public class Main { public static void main(String... args)…
Kowser
  • 8,123
  • 7
  • 40
  • 63
2
votes
3 answers

Android: NullPointerException on getWritableDatabase()

Here is where I try to access the database: UserDataAdapter dbHelper = new UserDataAdapter(this); dbHelper.open(); dbHelper.createNetwork(network); dbHelper.close(); UserDataAdapter.java: public UserDataAdapter open() throws SQLException { …
2
votes
1 answer

NullPointerException to JpaRepository in Spring project on Servlets

I have an entity: @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String login; private String password; public User() { } public User(String login, String password) { this.login =…
2
votes
2 answers

Javamail works on Windows, not on Linux

I'm having a really frustrating problem with Javamail. So, simple non-encrypted, no-attachment e-mail works both in linux and Windows. When I try to send attachment along with it, or send an e-mail using TLS encryption, javamail crashes on linux…
Don Spike
  • 21
  • 1
2
votes
0 answers

My app is crashed whenever I am using MediaControllers of a VideoView in android (on pausing video)

I am playing a video in my app through videoview. When I am clicking on pause button of MediaController, my app is crashing. Here is my code: Uri uri = Uri.parse(videoUrl); chatVideoView.setVideoURI(uri); MediaController…
2
votes
1 answer

Android fragment DataBinding nonnull getter return null

As per the android documentation, To get the data binding within a fragment, I use a non-nullable getter, but sometimes' When I try to access it again, after I'm wait for the user to do something, I receive a NullPointerException. private var…
2
votes
1 answer

How can a stacktrace show an NPE from code that can't throw an NPE?

Given code that hasn't been touched for two years, and that never saw such a problem before, is there any explanation for this stack trace: at java.lang.Thread.run(Thread.java:818)\nCaused by: java.lang.NullPointerException at…
GhostCat
  • 137,827
  • 25
  • 176
  • 248
2
votes
1 answer

JavaFX corrupted Image from Server makes app crash

I'm trying to convert Base64 Image Strings and some URLs to image form but one or more of the images I get from the server seem to be corrupted. I can pick them out per hand but I need a code solution for this. I wrote the method prepareAvatar which…