I have tried this.
// code snip start
URL url = new URL(string);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
is.close();
con.disconnect();
// code snip stop
It doesn't help.

FYI, when I added a while loop, like this
while(bmp == null)
{
  Thread.sleep(100);
  URL url = new URL(string);
  Bitmap bmp = BitmapFactory.decodeStream(url.openStream());
}

After one/two try, it always return a valid Bitmap.

But I think it just a workaround. Is there any stand way to fix it?

On Apr 24, 1:08 pm, "Jack Ha (T-Mobile USA)" <[email protected]>
wrote:
> You may want to try adding the following line before "return bmp;"
>
>     con.disconnect()
>
> --
> Jack Ha
> Open Source Development Center
> ・T・ ・ ・Mobile・ stick together
>
> The views, opinions and statements in this email are those of
> the author solely in their individual capacity, and do not
> necessarily represent those of T-Mobile USA, Inc.
>
> On Apr 23, 6:29 am, Alex <[email protected]> wrote:
>
> > I have written a method, like this
> > private Bitmap getBitmapFromUrl(String urlString)
> > {
> >   try  {
> >     URL url = new URL(urlString);
> >     HttpURLConnection con = (HttpURLConnection)url.openConnection();
> >     InputStream is = con.getInputStream();
> >     Bitmap bmp = BitmapFactory.decodeStream(is);
> >     return bmp;
> >   }catch(Exception e)
> >   {
> >     return null;
> >   }
>
> > };
>
> > When I call this method continuously in a thread, it returns a valid
> > bitmap only at the first call, as for the following call, LogCat would
> > report "jpeg error 20 Improper call to JPEG library in state".
>
> > Actually, I think the problem is because of the connection error,
> > since when I debug the application, the inputstream seems invalid.
>
> > Is there anyone know what the problem is it?
> > Thanks in advance.
>
>
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to