Android warning response.body().string();
See original GitHub issueHello.
I am getting this warning in this code: myString = response0.body().string();
Method invocation ‘string’ may produce ‘java.lang.NullPointerException’
The problem appears in string()
. This code is inside try-catch.
How can I solve this safety? I searched in StackOverflow but I found nothing.
The app is working perfectly, it is just a warning.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Retrofit response.errorBody.string() gives me warning of ...
When I do response.errorBody()?.string() , Android Studio gives me a warning saying "inappropriate blocking method call".
Read more >okhttp3.ResponseBody.source java code examples - Tabnine
string. Returns the response as a string decoded with the charset of the Content-Type header. · byteStream · contentType · contentLength. Returns the...
Read more >5.4.1 release causes okhttp error response body to be ...
I.e. calling response.body().string() in the onResponse callback ... a new version of the Android agent 5.5.0 has been released with a fix.
Read more >ResponseBody - OkHttp - Square Open Source
bytes(); Response.body().string(). There is no benefit to invoking multiple close() methods for the same response body. For synchronous calls ...
Read more >okhttp responsebody can not be converted to a string. Please ...
newCall(request); call.enqueue(new Callback() { @Override public void ... "Check Log " + response.body().string()); String jsonData ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The warning can be suppressed for a normal response. The body is only null for a cached response or network response.
replace
response.body().string()
withString successResponse = new Gson().toJson(response.body());
full code: