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...



