0

I am facing an issue while trying to retrieve value from JSONObject. I've spent an hour researching the solution, but non of suggestions work in other posts or anywhere else.

When I run above code on emulator, it throws error and I am able to catch it.

JSONException: No value for property

However If I put a breakpoint in try block and run the app, with Android Studio's Evaluate Expression tool I am able to get non empty value with the same code, and it does not throw exception. So the initial JSONObject userInfo definitely contains the data I am trying to get, and it works if I run it in debug mode by hands.

Here is my code.

    String value = "";
    try {
        JSONObject obj = userInfo.getJSONObject("data");
        value = obj.getString(param);
    } catch (JSONException e) {
        e.printStackTrace();
    }

Emulator is configured with standard Nexus 5 configs with android studio.

Artur Aleksanyan
  • 480
  • 5
  • 10

1 Answers1

0

After spending some time researching, I found the problem. It was because I previously modified gradle to be able to use java 8 lambdas.

So reverting project JDK back to 7 worked for me. I hope this will save somebody's time.

Community
  • 1
  • 1
Artur Aleksanyan
  • 480
  • 5
  • 10