मेरे पास छवि आइकन (जो ड्रॉबल्स फ़ोल्डर में संग्रहीत हैं) के साथ 70 टेक्स्ट आइटम की एक सूची है। यदि मैं पहली बार एप्लिकेशन लॉन्च करता हूं और धीरे-धीरे सूची स्क्रॉल करता हूं - अपवाद नहीं होता है।छवियों की सूची स्क्रॉल करते समय OutOfMemory अपवाद प्रकट होता है
जब आवेदन पहली बार शुरू की है और मैं निम्नलिखित अपवाद तब होता है 'फ़्लिंग' कार्रवाई के साथ सूची स्क्रॉल:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:439)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:322)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:688)
at android.content.res.Resources.loadDrawable(Resources.java:1710)
at android.content.res.Resources.getDrawable(Resources.java:585)
उसके बाद, अगर मैं डी डी एम एस के साथ आवेदन को मारने, उसे बार-पुस्तक शुरू यह 'फ़्लिंग' कार्रवाई के साथ, अपवाद नहीं होता है। तो अपवाद तब उत्पन्न होता है जब एप्लिकेशन इंस्टॉल हो और पहली बार लॉन्च हो।
public class AuthorAdapter extends ArrayAdapter<Author> {
private ArrayList<Author> items;
private Context context;
private LayoutInflater inflater;
public AuthorAdapter(Context context, int textViewResourceId, ArrayList<Author> items) {
super(context, textViewResourceId, items);
this.items = items;
this.context = context;
inflater = LayoutInflater.from(this.context);
}
static class ViewHolder {
ImageView authorFace;
TextView authorName;
TextView authorWho;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.autor_data, null);
holder = new ViewHolder();
holder.authorFace = (ImageView) convertView.findViewById(R.id.authorFaceImageView);
holder.authorName = (TextView) convertView.findViewById(R.id.authorNameTextView);
holder.authorWho = (TextView) convertView.findViewById(R.id.authorWhoTextView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Author author = items.get(position);
if (author != null) {
if (holder.authorFace != null) {
String faceFileName = author.getFace();
String facePlaceName = context.getPackageName() + ":drawable/" + faceFileName.subSequence(0, faceFileName.lastIndexOf("."));
int faceFileId = context.getResources().getIdentifier(facePlaceName, null, null);
holder.authorFace.setImageResource(faceFileId);
}
if (holder.authorName != null) {
holder.authorName.setText(author.getName());
}
if (holder.authorWho != null) {
holder.authorWho.setText(author.getWho());
}
}
return convertView;
}
}
वहाँ एक रास्ता अपवाद से बचने के लिए है:
यहाँ अनुकूलक मैं सूची के लिए उपयोग है? क्या मुझे अपवाद पकड़ना चाहिए और स्मृति को किसी भी तरह से बचाना चाहिए?
कोई सलाह कैसे इसे पूरा करने के लिए?
धन्यवाद।
आपकी छवियां कितनी बड़ी हैं –
सूची आइटम छवियां लगभग 3KB हैं। मैं दो सक्रियता (मुख्य और सूची) का उपयोग करता हूं। गतिविधि पृष्ठभूमि छवियां लगभग 60 केबी हैं। इसके अलावा छवियों का उपयोग मैं यूआई नियंत्रणों के लिए करता हूं, कुल में लगभग 100 केबी। क्या यह एक सिम्युलेटर समस्या हो सकती है? दुर्भाग्य से मैं इस समय डिवाइस पर अपने ऐप को आजमा नहीं सकता। – Zzokk