我正在使用以下代码从 url 获取位图。此函数在我的代码中多次使用,并且在第三次或第四次调用崩溃时显示以下错误。Url 存在,我确信以前的调用没有区别。谢谢
public static Bitmap getBitmapFromURL(String src) {
try {
Log.e("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input); //crashes at this line
Log.e("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}
06-15 14:15:34.365: E/AndroidRuntime(863): FATAL EXCEPTION: main
06-15 14:15:34.365: E/AndroidRuntime(863): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-15 14:15:34.365: E/AndroidRuntime(863): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
06-15 14:15:34.365: E/AndroidRuntime(863): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
06-15 14:15:34.365: E/AndroidRuntime(863): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
06-15 14:15:34.365: E/AndroidRuntime(863): at com.nimbosolutions.projecte1.TabBar_iOSActivity.getBitmapFromURL(TabBar_iOSActivity.java:232)
06-15 14:15:34.365: E/AndroidRuntime(863): at com.nimbosolutions.projecte1.TabBar_iOSActivity.addTab(TabBar_iOSActivity.java:209)