Parse JSON Data | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/10376651-android-networking-fundamentals/lessons/7

I am getting the following error from this line in RemoteApi:
onTasksReceived(tasksResponse.notes ?: listOf(), null)

Elvis operator ( ?: ) always returns the left operand of non-nullable type List

It’s the only Error/Warning I get during the build, and I always get “No Data! Create Some Notes!” when I load the app.

If I add a note it shows up, but still has the “No Data” error displayed. If I log back in, no notes are displayed.

Suggestions?

Hey @dizzy49!

The warning you get is probably because the tasksResponse.notes is not-nullable, and as such the elvis never returns the right-hand side.

I’m not sure why you get the error though, are you sure you’re parsing data correctly from the server?

In the getTasks function I am using:

val tasksResponse = gson.fromJson(response.toString(), GetTasksResponse::class.java)
onTasksReceived(tasksResponse.notes ?: listOf(), null)

Which matches what was in the video.

1 Like

Hey @dizzy49 !

There’s an issue here in the video, where I add the connection.doOutput = true statement, when building the GetTasks connection.

It should only have connection.doInput = true. Let me know if this fixes your issues! Really sorry that I had missed this important part.

Hi,

I am having an error on the response from the server when loading app and for fetching the tasks in getTasks in RemoteApi class :

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

I verified that my code matched what is in the repo for this function and also directly copied and pasted to double check.

Hey there @khwalke4!

You should be using HTTP for your device/phone and it should work fine. It’s best to have a physical device or to use an emulator to fetch the data withotu security issues.

There’s a similar issue here: [SOLVED]Android - Trust anchor for certification path not found - #2 by wthess - Seafile Client - Seafile Community Forum

And I think most people just defaulted to HTTP vs HTTPS and/or used the latest emulators which handle these things automatically!

Let me know if that works!