Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The message is pretty self explanatory... You're running out of memory.</p> <p>Check the parameters that you're passing to this method, there might simply be too many bitmaps being decoded and stored in memory.</p> <p>Consider caching instead of pre-loading all the bitmaps - only load the bitmap when you actually need to use it. Then add it to a hasmap (from its ID to the actual bitmap). Before decoding a bitmap check if it is already in the map, if it is you don't need to decode it again. Be sure to check the size of the map before decoding new bitmaps, and clear the cache when necessary so you don't run out of memory.</p> <p>Edit: Here's an example for how you could do it</p> <p>Edit2: Here's the full class code. Hope I didn't make any typos.</p> <pre><code>public class CurrencyRateListAdapter extends BaseAdapter { // This variable is used for debug log (LogCat) private static final String TAG = "CC:CurrencyRateListAdapter"; private LayoutInflater mInflater; private String[] mName; private Integer[] mBitmapIds; private HashMap&lt;Integer, Bitmap&gt; mBitmaps; private Context mContext; private Cursor mRateData; private double mRate[]; private String mDisplayrate[]; private int mBaseCurrencyPosition; public CurrencyRateListAdapter(Context context, Integer[] name, Integer[] bitmapID, Cursor rate_data) { mInflater = LayoutInflater.from(context); mBitmaps = new HashMap&lt;Integer, Bitmap&gt;(); mBitmapIds = bitmapID; mContext = context; mName = new String[name.length]; for(int j=0; j&lt;name.length; j++) { mName[j] = context.getString(name[j]); } mRateData = rate_data; // update currency rate updateCurrencyRate(); // set default currency mBaseCurrencyPosition = 0; } @Override public void finalize() { Log.d(TAG, "Close SQL cursor..."); mRateData.close(); } public int getCount() { return mBitmapIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; //Log.d(TAG, "&gt;&gt;&gt;&gt;&gt; getView: position=" + Integer.toString(position)); try { if(convertView == null) { // uses currencyratelist.xml to display each currency selection convertView = mInflater.inflate(R.layout.currencyratelist, null); // then create a holder for this view for faster access holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.ratelist_icon); holder.name = (TextView) convertView.findViewById(R.id.ratelist_text); holder.rate = (TextView) convertView.findViewById(R.id.ratelist_ratetext); // store this holder in the list convertView.setTag(holder); } else { // load the holder of this view holder = (ViewHolder) convertView.getTag(); } holder.icon.setImageBitmap(getIcon(mBitmapIds[position])); holder.name.setText(mName[position]); holder.rate.setText(mDisplayrate[position]); } catch (Exception e) { Log.e(TAG, "getView:" + e.toString()); } //Log.d(TAG, "&lt;&lt;&lt;&lt;&lt; getView: position=" + Integer.toString(position)); return convertView; } public void SetBaseCurrencyIndex(int value) { mBaseCurrencyPosition = value; // update display rate double rate_base = 1.0; if(mBaseCurrencyPosition &lt; mRate.length) { rate_base = mRate[mBaseCurrencyPosition]; } mDisplayrate = new String[mRateData.getCount()]; for(int i=0; i&lt;mRateData.getCount(); i++) { mDisplayrate[i] = String.format(Locale.US, "%.3f", mRate[i] / rate_base); } } public String getDisplayString(int position) { String result = "1.000"; if(position &lt; mRate.length) { result = mDisplayrate[position]; } return result; } public void updateCurrencyRate() { Log.d(TAG, "&gt;&gt;&gt;&gt;&gt; updateCurrencyRate"); // update currency rate data mRateData.requery(); mRate = new double[mRateData.getCount()]; int cnt = mRateData.getCount(); int colcnt = mRateData.getColumnCount(); for(int i=0; i&lt;cnt; i++) { if(mRateData.moveToPosition(i) == true) { if(colcnt == 1) { // only currency rate data in the query result set mRate[i] = mRateData.getDouble(0); } else { // all data in the query result set // So the rate data in the 2nd column (refer to CurrencyConverterDB class mRate[i] = mRateData.getDouble(1); } } else { mRate[i] = 1.0; } } // deactive currency rate data mRateData.deactivate(); Log.d(TAG, "&lt;&lt;&lt;&lt;&lt; updateCurrencyRate"); } public double getCurrencyRate(int position) { double rate_sel = 1.0; if(position &lt; mRate.length) { rate_sel = mRate[position]; } return rate_sel; } /* class ViewHolder */ private class ViewHolder { ImageView icon; TextView name; TextView rate; } private Bitmap getIcon(Integer bitmapId) { Bitmap icon = mBitmaps.get(bitmapId); if (icon == null) { icon = BitmapFactory.decodeResource(mContext.getResources(), bitmapId); mBitmaps.put(bitmapId, icon); } return icon; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload