java.lang.OutOfMemoryError: bitmap size exceeds VM test_app

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

java.lang.OutOfMemoryError: bitmap size exceeds VM test_app

Postby netmercury » Sun Nov 16, 2008 5:53 pm

Hi gurus,

Currently, I faced problem with java.lang.OutOfMemoryError: bitmap size exceeds VM test_app.

In my app, i have a listView and with a custom adapter for it.
The list view is working just fine, showing all the data in the list just as i wish,
however, when i try to keep on doing scrolling up and down for few times (around 10 times), the apps crashed and I got this error in logcat.

then i try to use SimpleCursorAdapter for the listview, the problem is not happened anymore.

I checked into my custom adapter, couldnt find any problem.

May I know what is the problem?

I paste my code of the custom adapter below, hope someone can help me out of this.

Code: Select all
package com.android.test.view;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

import com.android.test.R;
import com.android.test.adapter.TestListAdapter;

public class TestListView extends Activity {
   
   private ListView lvData;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.test_list);

   lvData = (ListView) findViewById(R.id.lvData);

        fillData();
    }

    private void fillData() {
       
        ArrayList<String> expensesList = new ArrayList<String>();
       

        for(int x=0;x<200;x++)
        {
          expensesList.add(x+"");
        }
       
       
        TestListAdapter eAdapter = new TestListAdapter(lvData.getContext(),expensesList);
        lvData.setAdapter(eAdapter);
    }
}





package com.android.test.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

class TestListAdapterView extends LinearLayout {       
        public TestListAdapterView(Context context, String test) {
            super( context );
           
            this.setOrientation(HORIZONTAL);       
            LinearLayout.LayoutParams testParams =
                new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
            testParams.setMargins(1, 1, 1, 1);

            TextView txtTest = new TextView( context );
            txtTest.setText(test);
            txtTest.setTextSize(14f);
            txtTest.setTextColor(Color.WHITE);
            addView( txtTest, testParams);         
        }
}

public class TestListAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<String> testList;

    public TestListAdapter(Context context, ArrayList<String> testList) {
        this.context = context;
        this.testList = testList;
    }

    public long getItemId(int position) { 
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
       
       String test = testList.get(position);
        return new TestListAdapterView(this.context, test );
    }

   public int getCount() {
      return testList.size();
   }

   public Object getItem(int position) {
      testList.get(position);
      
      return null;
   }

}


Thank you!

Attached with the test project workspace, hope anyone can help me out of this.
Please download, then run the emulator, try to scroll up and down of the list for few times.

Thank you!

Lastly, i actually wonder if this is only happen in emulator or in the real gphone as well.
I couldnt test it because i do not have a set of gphone...
Attachments
test.rar
test project workspace
(412.28 KiB) Downloaded 39 times
netmercury
Freshman
Freshman
 
Posts: 3
Joined: Sun Nov 16, 2008 5:33 pm

Top

Postby miguelo » Fri Nov 21, 2008 2:27 pm

We have the same problem in our project...and we haven't yet found a solution :-(

But I give you a couple of advices:

1.- Try to redefine the finalize method of your Activity class and log it to knows if it's finalizing successfully...

2.- In this post of android-developper groups are being trying to generate a dump memory file to can determine where the memory is lost...(http://groups.google.com/group/android- ... ee3e?hl=en)

I hope it helps you and other with a similar problem...

If someone discoverer something related with memory and the dump files, please let us know...

Regards, Miguel.

Sorry for my english :-(
miguelo
Freshman
Freshman
 
Posts: 6
Joined: Mon Nov 17, 2008 4:05 pm

Postby netmercury » Sat Nov 22, 2008 6:41 pm

thank you for your reply and advices.
I appreciate it.
I will look into it, thank you very much.
netmercury
Freshman
Freshman
 
Posts: 3
Joined: Sun Nov 16, 2008 5:33 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests