hey there guys and girls i have this code that should download a json object and then save it to internal memory, i keep getting stuck here
try{
//co
This is weird case, I edited my previous answer to fix this problem of yours. However: another question was asked, so here goes this portion of my previous answer:
About the error you get - you are trying to cast the entity of the response directly to an Integer. This will always fail, because Integer is not superclass of HttpEntity
. You need to read the contents of the entity in a String
and then parse the contents of the string to integer:
InputStream entityStream = entity.getcontent();
StringBuilder entityStringBuilder = new StringBuilder();
byte [] buffer = new byte[1024];
int bytesReadCount;
while ((bytesReadCount = entityStream.read(buffer)) > 0) {
entityStringBuilder.append(new String(buffer, 0, bytesReadCount));
}
String entityString = entityStringBuilder.toString();
writer.wrtie(entityString);
this is not highly optimized, but does the job. From then on you can use the responseInteger
value as you like . However if you want to do writer.write
you will need String
value, not Integer
. Thus I recommend you to use entityString
.