IllegalStateException: Content has been consumed

前端 未结 4 2052
你的背包
你的背包 2020-12-08 10:17

I got struck because of IllegalStateException in the following code. Can anybody please help me? Code:

import java.io.BufferedReader;
import jav         


        
4条回答
  •  孤城傲影
    2020-12-08 10:35

    You can consume Content only at once from an Entity

    in the line :

    final JSONObject jObject = new JSONObject(EntityUtils.toString(resEntity));
    

    you have consumed content and again you are using the same at here:

    Log.e("XXX",EntityUtils.toString(resEntity));
    

    That why it is causing IllegalStateException: Content has been consumed

    So the solution is here:

    String _response=EntityUtils.toString(resEntity); // content will be consume only once
    final JSONObject jObject=new JSONObject(_response);
    Log.e("XXX",_response);
    

提交回复
热议问题