- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Possible Duplicate:
bitmap size exceeds Vm budget error android
我开发了一个android示例。这里我得到了以下错误:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
这里我的控制台窗口显示以下错误:
11-23 22:15:55.933: E/dalvikvm-heap(2522): 22458-byte external allocation too large for this process.
11-23 22:15:55.933: E/GraphicsJNI(2522): VM won't let us allocate 22458 bytes
11-23 22:15:55.993: D/AndroidRuntime(2522): Shutting down VM
11-23 22:15:55.993: W/dalvikvm(2522): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-23 22:15:56.054: E/AndroidRuntime(2522): FATAL EXCEPTION: main
11-23 22:15:56.054: E/AndroidRuntime(2522): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ssmobileproductions.catalogue/com.ssmobileproductions.catalogue.SingleMenuItem}: android.view.InflateException: Binary XML file line #93: Error inflating class android.widget.ImageButton
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.os.Looper.loop(Looper.java:123)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 22:15:56.054: E/AndroidRuntime(2522): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 22:15:56.054: E/AndroidRuntime(2522): at java.lang.reflect.Method.invoke(Method.java:521)
11-23 22:15:56.054: E/AndroidRuntime(2522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 22:15:56.054: E/AndroidRuntime(2522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 22:15:56.054: E/AndroidRuntime(2522): at dalvik.system.NativeStart.main(Native Method)
11-23 22:15:56.054: E/AndroidRuntime(2522): Caused by: android.view.InflateException: Binary XML file line #93: Error inflating class android.widget.ImageButton
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
11-23 22:15:56.054: E/AndroidRuntime(2522): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-23 22:15:56.054: E/AndroidRuntime(2522): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.Activity.setContentView(Activity.java:1647)
11-23 22:15:56.054: E/AndroidRuntime(2522): at com.ssmobileproductions.catalogue.SingleMenuItem.onCreate(SingleMenuItem.java:35)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-23 22:15:56.054: E/AndroidRuntime(2522): ... 11 more
11-23 22:15:56.054: E/AndroidRuntime(2522): Caused by: java.lang.reflect.InvocationTargetException
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.widget.ImageButton.<init>(ImageButton.java:78)
11-23 22:15:56.054: E/AndroidRuntime(2522): at java.lang.reflect.Constructor.constructNative(Native Method)
11-23 22:15:56.054: E/AndroidRuntime(2522): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
11-23 22:15:56.054: E/AndroidRuntime(2522): ... 22 more
11-23 22:15:56.054: E/AndroidRuntime(2522): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.Bitmap.nativeCreate(Native Method)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.content.res.Resources.loadDrawable(Resources.java:1709)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.widget.ImageView.<init>(ImageView.java:118)
11-23 22:15:56.054: E/AndroidRuntime(2522): at android.widget.ImageButton.<init>(ImageButton.java:82)
11-23 22:15:56.054: E/AndroidRuntime(2522): ... 26 more
这是我的位图代码:
private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);
//from SD cache
Bitmap b = decodeFile(f);
if(b!=null)
return b;
//from web
try {
Bitmap bitmap=null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
}
//decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f){
try {
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
请帮助我如何解决此错误。
最佳答案
您可以使用opts.inSampleSize=2; or opts.inSampleSize=4
解决该问题(question)
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize=2;
Bitmap bitmap = decodeFile(f,opts);`
本文还提供了一些可能有帮助的提示:
http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html
关于java - 位图大小超出 Android 中的 VM 预算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13639277/
在文档中我们可以找到 The limits are based on a moving window that tracks the number of requests you send per h
我试图了解使用 Windows Azure 托管 Web 服务的正确方法。在阅读了一些可用的文档后,我已经达到以下几行: Windows Azure takes the following actio
我正在使用 unboundid ldap sdk 来执行 ldap 查询。运行 ldap 搜索查询时遇到一个奇怪的问题。当我对包含 50k 个条目的组运行查询时出现异常。我的异常(exception)
我有以下 docker-compose 文件: version: "2.4" services: auto_check: image: python mem_limit: 97M
我有副本集(托管在亚马逊上),其中有: 主要 中学 仲裁者 它们都是 3.2.6 版本,这个副本正在我的分片集群中创建一个分片(如果这很重要,尽管我认为它不重要)。 当我在 primary 上键入 r
我知道在 C++ 中访问缓冲区边界是未定义的行为。 这是来自 cppreference 的示例: int table[4] = {}; bool exists_in_table(int v) {
嗨,我有一个表单的 div。我希望当鼠标离开 div 时禁用单击事件。所以我尝试了这个,但它不起作用,div 仍然可以点击。有什么想法吗?? var flag = false; $("#foo").l
我正在使用我的客户端获取有关存储在我的 Swift 对象存储中的某个文件的一些信息,该文件可以通过 REST Api 访问。在 Swift 中,指向指定对象的 HEAD 方法和 url 返回它的元数据
如何在 Excel 的 CONCATENATE 函数中使用超过 255 个字符?我实际上也在 EXCEL 的 HYPERLINK 函数中使用 CONCATENATE 函数。一个例子如下: =HYPER
在 java 6 web 应用程序中,我尝试从执行的命令中检索大量输出。我在 javaworld article 上“借用/窃取/基于”它。我面临的问题是,由于输出被截断,长度似乎超出了大小限制。我已
我有一个更改事件,当选择框更改时会触发该事件。然而,选择框位于被替换的 div 内,因此会重新生成选择框。由于此错误可能是由于无限循环造成的,因此我猜测创建选择框时也必须触发我的触发事件。我尝试了很多
我正在 visual studio 2013 中用 c# 创建一个网络服务。我已连接到数据库并使用以下代码返回 json。 [WebMethod] [ScriptMethod(ResponseForm
我使用 php 脚本解析远程 xml 文件并将网页上的输出打印到 div 中。由于我需要输出必须与当前播放的轨道同步,所以我使用 Javascript 每 20 秒重新加载一次 div 内容。在测试页
#define MAX_BUFF_SIZE 64 char input[MAX_BUFF_SIZE]; int inSize = read(0, input, MAX_BUFF_SIZE); if
我在申请公司时遇到了问题。 我将总结系统的关键要素: 我公司的系统几年前就在 Windows XP 和 7(家庭版、专业版、基本版)机器上运行。 它是用 .NET 4.0 编写的,基于 WCF。 它使
我有一个渲染循环,用于监听数位板输入并从顶点/索引缓冲区(以及其他内容)中绘制。顶点数据可以增长,当它达到一定水平时,DispatchMsg(&msg) 会遇到这种情况: Unhandled exce
我通过 Postgres JDBC 驱动程序使用 Java 1.7 和 Postgres。将从 Web 服务使用数据库连接。在测试中,我得到了以下错误: FATAL: connection limit
我想知道当超过 Firebase 实时数据库的限制时会发生什么。问题是我知道我可以拥有的最大连接数仅为 100。现在,假设我的 Android 应用程序有 1,000 个活跃用户,并且我实现了实时数据
我正在将一组图像上传到我的 node.js Express 服务器,但收到错误 - “错误:超出 maxFieldsSize”。看起来默认的 maxFieldsSize 是 2MB。我需要能够上传最多
我正在使用 Django 构建一个小型 Web 项目,该项目有一个包含 ImageField 的模型 (Image)。当我尝试使用管理界面上传图片时,我遇到了这个问题(删除了个人身份信息): Runt
我是一名优秀的程序员,十分优秀!