【发布时间】:2014-08-01 01:55:11
【问题描述】:
这与这个问题有关
java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
我创建了有问题的转储文件.. 它提供了以下信息
One instance of "byte[]" loaded by "<system class loader>" occupies 1,10,59,216
(51.02%) bytes. The memory is accumulated in one instance of "byte[]"
loaded by "<system class loader>".
Keywords byte[]
那么现在可以做什么?我如何清除问题?
我的 list_objects[context]-入站文件
CLASS NAME SHALLOW HEAP RETAINED HEAP
byte[11059200] @ 0xb4979590 | 1,10,59,216 | 1,10,59,216
mBuffer android.graphics.Bitmap @ 0xb3dc68d8 |48 | 48
mBitmap android.graphics.drawable.BitmapDrawable @ 0xb3dbba60 | 72 | 144
mBackground android.widget.RelativeLayout @ 0xb3db3fc0 |512 | 10,144
mBitmap android.graphics.drawable.BitmapDrawable$BitmapState @ 0xb3dc0068 |40 | 40
mBitmapState android.graphics.drawable.BitmapDrawable @ 0xb3dbba60 |72 | 144
referent java.lang.ref.WeakReference @ 0xb3dc2d68 |24 | 24
请帮助我绝望。如何解决内存问题??
我的 home_screen.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_page);
main();
private void main() {
// TODO Auto-generated method stub
final Button home;
final Button aboutus;
final Button contacts;
final Button clients;
final Button services;
try
{
home = (Button)findViewById(R.id.btnHome);
aboutus = (Button)findViewById(R.id.btnAboutus);
clients = (Button)findViewById(R.id.btnClients);
contacts = (Button)findViewById(R.id.btnContacts);
services = (Button)findViewById(R.id.btnServices);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.home1);
Drawable d = new BitmapDrawable(getResources(),b);
home.setBackgroundDrawable(d);
System.gc();
Intent myIntent = new Intent(Home_Screen.this, Button_Anime.class);
startActivity(myIntent);
}
});
aboutus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.about1 );
Drawable d = new BitmapDrawable(getResources(),b);
aboutus.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, AboutUs.class);
startActivity(myIntent);
}
});
clients.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.clients1 );
Drawable d = new BitmapDrawable(getResources(),b);
clients.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Clients.class);
startActivity(myIntent);
}
});
contacts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.contact1);
Drawable d = new BitmapDrawable(getResources(),b);
contacts.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Contacts.class);
startActivity(myIntent);
}
});
services.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.services1 );
Drawable d = new BitmapDrawable(getResources(),b);
services.setBackgroundDrawable(d);
Intent myIntent = new Intent(Home_Screen.this, Services.class);
startActivity(myIntent);
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
【问题讨论】:
-
粘贴您的代码。以便我们进行分析。
-
@DevCarlsberg 我已经发布了我的主文件.. 请检查..
-
老兄通过My this Answer会帮助你。
-
我已经完成了所有这些.. 并且仍然遇到同样的错误.. 我的文件都是 30-40kb 大小,是的,我已将堆设置为大@DevCarlsberg
-
好的,让我给你解码你的位图的代码。它会解决你的问题
标签: java android out-of-memory heap-memory