Skip to content Skip to sidebar Skip to footer

Trying To Download Json From Mysql

hey there guys and girls, iv been trying to fix this problem for weeks now and carnt seem to get any help, i want the code to download a JSON file from my server and the save it to

Solution 1:

If this really is your Manifest file, the error is obvious .The tags should not be use[r]s-permission, but uses-permission:

<uses-permissionandroid:name="android.permission.INTERNET"  /><uses-permissionandroid:name="android.permission.SET_DEBUG_APP" />

Now you wouldn't have access to internet, and thus the error. If you switch to using an IDE like Eclipse and use autocomplete you will avoid such errors from the very beginning, but furthermore the IDE will underline this mistakes as warnings.

EDIT: 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:

InputStreamentityStream= entity.getcontent();
StringBuilderentityStringBuilder=newStringBuilder();
byte [] buffer = newbyte[1024];
int bytesReadCount;
while ((bytesReadCount = entityStream.read(buffer)) > 0) {
    entityStringBuilder.append(newString(buffer, 0, bytesReadCount));
}
StringentityString= entityStringBuilder.toString();
IntegerresponseInteger= Integer.valueOf(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.

Solution 2:

You inserted the permission wrong. It has to be something like this

<manifestxlmns:android...>
 ...
 <uses-permissionandroid:name="android.permission.INTERNET"></uses-permission></manifest>

You used:

<users-permission ...

Where do you get the String nullpointer?

Post a Comment for "Trying To Download Json From Mysql"