How can I avoid this NullPointerException?

Source Code

I have the following situation, where my program terminates with a NullPointerException during the function. What can I do to make this function work?

UPDATE

else if (str == null)
    emptyLinks.add(newPageLinks.get(i).getText() + "at link: " + str);
brso05

The problem is not in:

else if (str == null) 

The actual problem is in:

do something

In your do something you are trying to access a property or method of a null object which isn't possible and will throw an NPE.

Normally if you want to access methods from an object that could be null you do a null check like so:

if (str != null)
do something

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i remove nullPointerException

From Dev

How do I avoid a NullPointerException when stopping and starting a Clip in Java?

From Dev

How can I avoid these case statements?

From Dev

How can I avoid the void assignment in this code?

From Java

How can I avoid complex for loops?

From Dev

How can I avoid code duplication?

From Dev

How can I avoid hardcoding a file path?

From Dev

How can I avoid using instanceof in this case?

From Dev

How can I avoid explicit decoding of content?

From Dev

How can I avoid this code duplication?

From Dev

How can I avoid Java downcasts?

From Dev

How can I avoid <<loop>> in Haskell?

From Dev

How can i avoid for loop for KNN search?

From Dev

How can I avoid a nested form situation?

From Dev

How can I avoid migration in RealmSwift

From Dev

How can I fix to avoid a memory leak?

From Dev

How can I avoid <<loop>> in Haskell?

From Dev

How can i avoid ArrayIndexOutOfBoundsException in this case?

From Dev

How can I avoid a memory leak in this function?

From Dev

How can I avoid this code duplication?

From Dev

Django conditional queries: How can I avoid this?

From Dev

How can I avoid dntypes.ExcelErrorName()

From Dev

How can I avoid duplicate templates in Meteor?

From Dev

How i can avoid the distinct() of watchdog?

From Dev

How can I avoid kernel updates?

From Dev

How can I avoid duplicate items in a checkListBox

From Dev

How can I avoid dependencies between methods?

From Dev

How can I avoid problems with CPU power?

From Dev

How can I avoid the Post Processing in Paperclip