Skip to content
Advertisement

Attempt to invoke interface method ‘int java.util.List.size()’ on a null object reference – while calling retrofit

I wrote an adapter and activity code to fetch the data. Code is given below.
Adapter:

JavaScript

Activity:

JavaScript

Running that code gives me this error:

java.lang.NullPointerException: Attempt to invoke interface method ‘int java.util.List.size()’ on a null object reference at com.dell.mycampus.view.adapter.DellTransportAdapter.getItemCount

Is customers initialized?

Advertisement

Answer

You should use addAll instead of =

addAll(Collection<? extends E> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s Iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Don’t

JavaScript

Do

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement