I want to get the errorBody's error message, which I do by calling errorBody().string() (tried with errorbody().byteStream() too). But no matter what, after reading it out, the response errorbody's message will be null. It's not an option to save out the string to a static variable, but the project requires to check the response multiple times in different scenarios. My question is how to get the errorBody's message without clearing it out?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
errorBody
is of typeResponseBody
is from OkHttp. The docs make it clear you can only read from it once. This is because it is a stream, not already stored in memory --You only get to call
.string()
(or other methods that access the stream once). If you need to access the value more than once you have to save it the first time you access it and use that cached value in later code. It doesn't have to be astatic
variable, it can be a regular variable, but you are responsible for passing it around your code just like any other piece of data you use in multiple places.