0

I get this Memory Error (bitmap size exceeds VM) when I scroll more than 5 elements of my Gallery. This is my last part of the app and I wish very badly to be finished. All my Gallery Images are 180x180. I have read some "memory error" topics on StackOverFlow but most of them tell me to convert my images into Bitmaps, which I don't know how it really works. If someone can post a solution code for my problem, I will be very grateful! Code here:

 public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);                  
        a.recycle();
    }

    public int getCount() {
        return mImageIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

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

        public View getView(final int position, View convertView,ViewGroup parent) {

            if (convertView == null) {
                       LayoutInflater inflater = (LayoutInflater) 
                       mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                       convertView=inflater.inflate(R.layout.l1,null); 

     }
    HighscoreManager hm=new HighscoreManager();
        hm.addScore(timePerWord);         
        ImageView imgView = (ImageView)convertView.findViewById(R.id.imageView1);

        TextView txtView = (TextView)convertView.findViewById(R.id.textView2);                
        if(hm.getHighscoreString()[position]!=0)
        txtView.setText("\t\t    Avg.time: "+hm.getHighscoreString()[position]

);  

            txtView.setTextSize(20);
            imgView.setImageResource(mImageIds[position]);      
            return convertView;

     }

Where the .xml file L1 is: (not much of it, an image and a textview below)

  <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/l1"
    android:layout_width="240dp"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="240dp"
        android:layout_height="185dp"
        android:layout_x="-1dp"
        android:layout_y="-15dp"
        android:src="@drawable/background" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="38dp"
        android:layout_x="0dp"
        android:layout_y="169dp"
        android:text=""
        android:gravity="center" />

</AbsoluteLayout>
AnTz
  • 127
  • 3
  • 11
  • May help: http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android (or many other results if you just search). – Charlie Collins Dec 01 '11 at 15:51
  • The Gallery Widget also has a bug that makes it never use recycled views. Which I imagine is not helping your memory problems any. Search online for EcoGallery and you can find a third party widget which fixes this bug. Its a bit more work to get it set up and running than the stock Gallery widget though unfortuneately – FoamyGuy Dec 01 '11 at 16:04
  • Don't know how to implement that in my code, Charlie. – AnTz Dec 01 '11 at 16:11
  • I don't really want to try the EcoGallery, I spent alot of time trying to make this one work. If I remove the LinearLayout and let only the Images there it works great. But I need a TextView below the Image aswell. Please someone find a good solution for this. – AnTz Dec 01 '11 at 16:13
  • There can be another option. Not letting the user slide more than 1 gallery image, but I don't have any idea how to use it. – AnTz Dec 01 '11 at 17:08

0 Answers0