shayla.sawchenko.net

getContent() throwing IllegalStateException?

01 September 2013 - Filed under android

While debugging my HttpResponse object in my Android application I kept coming across an the error while attempting to get my response content via response.getEntity().getContent():

IllegalStateException: Content has been consumed

I puzzled and puzzled until my puzzler was sore, and then I realized that I had put result.response.getEntity().getContent() in my watch window in an effort to debug the result. Turns out this is a bad idea!

Watch: Never call getContent() from your watch/expression window! Always write to a variable and watch the variable.

Calling .getContent() in the watch window causes the content to be consumed in the watch window, thus causing the above exception to be thrown when the application attempts to retrieve it.

References

StackOverflow Post

by Shayla Sawchenko