I\'m creating an app that display contact list in a listview.The problem is I\'m getting the following error when I run my app and I\'m struggling to fix it:
Extract this line
List<ContactModel> contactModelList = new ArrayList<>();
before the try block and instead of return null;
use return contactModelList;
Looks like your parsing fails and you pass a null
object to onPostExecute()
.
The List object which you passed into the adapter is null. So when the adapter calls list.Size(), a null pointer exception is thrown.
Use a debugger, set a breakpoint somewhere around com.kksworld.jsonparsing.MainActivity$JSONTask.onPostExecute(MainActivity.java:48), and work your way backward from there if you can't figure it out.
One assumes that your json parse failed somehow or another.
I was building similar app from youtube video and I've got same error, but I saw also error "Cleartext HTTP traffic not allowed to site.com", so I found solution android:usesCleartextTraffic="true"
here Android 8: Cleartext HTTP traffic not permitted and it solved all problems without modifying MainActivity.
Btw, on API 16 it wasn't showing errors.