Linked Questions
167 questions linked to/from How do I avoid checking for nulls in Java?
0 votes
1 answer
53 views
how to resolve Null Pointer Exception in android? [duplicate]
i'm working with fragments. I have created a List fragment and a Detail fragment. when i click on an item in the list the app crashes and it gives the following null pointer exception. Attempt to ...
0 votes
0 answers
46 views
BUG, activity does not load fragment with firebase data [duplicate]
my application so far is like this: in ActivityHome, it opens the Fragments using a "FragmentContainerView", my FragmentHome loads the firebase videos in a ViewPage2, using the design of an ...
1 vote
0 answers
45 views
Avoid duplicated code 'cause of null objects? [duplicate]
As you know, in a lot of cases we need to check if an object is null or not to execute a method. It`s really not good to code, it gets ugly and repetitive. And sometimes the null objects was excepted (...
-3 votes
1 answer
44 views
Problem with setOnClickListerner() when project is linked with github [duplicate]
Edit: I found the solution, for some reason the code does not run android studio if it is linked to the GitHub repository. I pushed the same version to a new branch on GitHub and downloaded the code ...
0 votes
0 answers
37 views
NullPointerException with mockito test [duplicate]
I am very new at writing tests and I am trying to write a simple one to check that the email the user writes for the login is valid. I got the way to do it from a tutorial and it makes sense the way ...
0 votes
0 answers
35 views
my emulator crashes when i run it with a recycler view [duplicate]
Just as the title says. I dont think my adapter and view holder are wrong (but then again its my first time using it), but upon launching the programme, my emulator crashes. Is it something to do with ...
0 votes
0 answers
25 views
set On Click Listener feature, an error occurs [duplicate]
I have a problem and I hope anyone can help me When I give the button id and go to Main Activity to use the button with the set On Click Listener feature, an error occurs Kotlin language
209 votes
12 answers
4.3m views
What is a NullPointerException, and how do I fix it?
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them? What methods/tools can be used to determine the cause so that you stop the exception from causing the program ...
756 votes
5 answers
253k views
Why is Java Vector (and Stack) class considered obsolete or deprecated?
Why is Java Vector considered a legacy class, obsolete or deprecated? Isn't its use valid when working with concurrency? And if I don't want to manually synchronize objects and just want to use a ...
373 votes
14 answers
188k views
Uses for Optional
Having been using Java 8 now for 6+ months or so, I'm pretty happy with the new API changes. One area I'm still not confident in is when to use Optional. I seem to swing between wanting to use it ...
392 votes
7 answers
121k views
Should Java 8 getters return optional type?
Optional type introduced in Java 8 is a new thing for many developers. Is a getter method returning Optional<Foo> type in place of the classic Foo a good practice? Assume that the value can be ...
205 votes
17 answers
87k views
When should assertions stay in production code? [closed]
There's a discussion going on over at comp.lang.c++.moderated about whether or not assertions, which in C++ only exist in debug builds by default, should be kept in production code or not. Obviously, ...
122 votes
16 answers
217k views
Java "?." operator for checking null - What is it? (Not Ternary!)
I was reading an InfoWorld article (link to Wayback machine since the excerpt was since removed), and came across this little tidbit: Take the latest version of Java, which tries to make null-pointer ...
62 votes
19 answers
115k views
Is it okay to throw NullPointerException programmatically? [closed]
When there is a post-condition, that return value of a method must not be null, what can be done? I could do assert returnValue != null : "Not acceptable null value"; but assertions could be turned ...
103 votes
11 answers
58k views
Check chains of "get" calls for null
Let's say I'd like to perform the following command: house.getFloor(0).getWall(WEST).getDoor().getDoorknob(); To avoid a NullPointerException, I'd have to do the following if: if (house != null &...