java - Bitmap OutOfMemoryError -


i have question error.

i make favicon parser urls. like:

public class grabiconsfromwebpage { public static string replaceurl(string url) {     stringbuffer sb = new stringbuffer();     pattern p = pattern.compile("https?://.+\\..+?\\/");     matcher m = p.matcher(url);     while (m.find()) {         sb.append(m.group());     }     return sb.tostring(); }  public static string getfavicon(string url) throws ioexception {     try {         document doc = jsoup.connect(url).get();         element element = doc.head().select("link[href~=.*\\.(ico|png)]").first();         if (element != null) {             if (element.attr("href").substring(0, 2).contains("//")) {                 return "http:" + element.attr("href");             } else if (element.attr("href").substring(0, 4).contains("http")) {                 return element.attr("href");             } else {                 return replaceurl(url) + element.attr("href");             }         } else {             return "";         }     } catch(illegalargumentexception ex) {         ex.printstacktrace();     } catch(outofmemoryerror er) {         er.printstacktrace();     }     return ""; }  public static bitmap getbitmapfromurl(string src) {     try {         url url = new url(src);         httpurlconnection connection = (httpurlconnection) url.openconnection();         connection.setdoinput(true);         connection.connect();         inputstream input = connection.getinputstream();         bitmap mybitmap = bitmapfactory.decodestream(input);         return mybitmap;     } catch (ioexception e) {         e.printstacktrace();         return null;     } } 

}

and how bitmap url

bitmap faviconbitmap = grabiconsfromwebpage.getbitmapfromurl(                                 grabiconsfromwebpage.getfavicon(                                         bookmarkdata.get(position).geturl() // url want grab favicon                                 )                         ); 

and code after uploading 20 images give me outofmemoryerror. how can fix this? or optimize? cuz in list show icons, can more 20 or 40 favicons...

i think, use universal image loader

the method given snippet

// load image, decode bitmap , return bitmap synchronously  imagesize targetsize = new imagesize(80, 50);  // result bitmap fit size bitmap bmp = imageloader.loadimagesync(imageuri, targetsize, options); 

and out of memory bound add line in manifest file

<application         ...         android:largeheap="true"         ...         > </application> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -