Maybe some of the requests are getting blocked. Try adding connect and
read timeouts by replacing url.openStream() with
openConnection().getInputStream():

...
URL url = uri.toURL();
URLConnection con = url.openConnection();
con.setConnectTimeout(3000);
con.setReadTimeout(3000);
Bitmap bmp = BitmapFactory.decodeStream(con.getInputStream());
...

Adjust the 3000 ms timeout values if necessary.

You can add exception handling for the connection timeouts.

Regards,

Kim

On Sep 1, 4:36 am, snowcrash <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I experience strange things when using the compress method from
> Bitmap. I'm useing the code at the bottom to download JPEGs from a
> server. Out of all images downloaded, ~10% fail to be written with a
> NullpointerException and a preceding message from something called
> 'skia'. Each image is different and it doesn't always happen for the
> same ones:
>
> 09-01 13:19:04.126: DEBUG/skia(1124): xxxxxxxxxxxxxx failure to skip
> request 9936 actual 6906
> 09-01 13:19:04.132: DEBUG/skia(1124): xxxxxxxxxxxxxxxxxxxxx jpeg
> setjump exit
> 09-01 13:19:04.132: ERROR/ImageUtil(1124):
> java.lang.NullPointerException
>
> If I use the same code on PNGs, all works like a charm.
>
> The code used is:
>
> public static String saveImageFromURI(URI uri, String name,
>                         final Activity ctx, Handler handler) {
>                 boolean success = false;
>                 String qualifiedName = name + ".jpg";
>                 FileOutputStream fos = null;
>                 try {
>                         URL url = uri.toURL();
>                         Bitmap bmp = 
> BitmapFactory.decodeStream(url.openStream());
>                         fos = ctx.openFileOutput(qualifiedName, 
> Context.MODE_PRIVATE);
>                         success = bmp.compress(Bitmap.CompressFormat.JPEG, 
> 75, fos);
>                 } catch (MalformedURLException e) {
>                         Log.e(TAG, e.toString(), e);
>                 } catch (IOException e) {
>                         Log.e(TAG, e.toString(), e);
>                 } catch (IllegalArgumentException e) {
>                         Log.e(TAG, e.toString());
>                 } catch (NullPointerException e) {
>                         Log.e(TAG, e.toString(), e);
>                 } finally {
>                         try {
>                                 if (fos != null)
>                                         fos.close();
>                         } catch (IOException e) {
>                                 Log.e(TAG, e.toString(), e);
>                         }
>                 }
>                 if (success) {
>                         return qualifiedName;
>                 } else {
>                         return null;
>                 }
>         }
>
> Any ideas what could cause this behaviour?
>
> snowcrash

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to