• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Store and call next_page_token

Hey guys so reading this helped me a lot but i am having a bit of a problem. When i use the same code modeified to fit my own code with parsing my JSON file it doesnt work. I am getting an error saying no value for next_page_token. When i open and view my JSON file i see it on the top of the page. Any suggestions? I can post the JSON file if that helps?
 
Hello I am having a problem with that "defensive null-checking" you were talking about. This is what i have but it is still giving me a problem. It says Invaild request.

if(jsonObject.getString("next_page_token") != null){
getNextToken();
}

Is this a correct way to check if its null?

Erorr log:
W/System.err: org.json.JSONException: No value for next_page_token
D/downloadUrl: { "html_attributions" : [], "results" : [], "status" : "INVALID_REQUEST"}
 
Hello I am having a problem with that "defensive null-checking" you were talking about. This is what i have but it is still giving me a problem. It says Invaild request.

if(jsonObject.getString("next_page_token") != null){
getNextToken();
}

Is this a correct way to check if its null?

Erorr log:
W/System.err: org.json.JSONException: No value for next_page_token
D/downloadUrl: { "html_attributions" : [], "results" : [], "status" : "INVALID_REQUEST"}

Your help here is the reference documentation for JSONObject

https://developer.android.com/reference/org/json/JSONObject.html

It states that

Code:
getString(String name)
Returns the value mapped by name if it exists, coercing it if necessary, or throws if no such mapping exists.

So that's why you get an exception thrown if the string doesn't exist. What you need to use is one of these methods:-

Code:
optString(String name)
Returns the value mapped by name if it exists, coercing it if necessary, or the empty string if no such mapping exists.

optString(String name, String fallback)
Returns the value mapped by name if it exists, coercing it if necessary, or fallback if no such mapping exists.

And your code becomes:

Code:
if (! jsonObject.optString("next_page_token").equals("")) {
    getNextToken();
}
 
Back
Top Bottom