0
我得到了logcat的錯誤:如何修復android中的「java.lang.OutOfMemoryError」?
12-10 17:49:21.393: E/AndroidRuntime(16350): FATAL EXCEPTION: main
12-10 17:49:21.393: E/AndroidRuntime(16350): java.lang.OutOfMemoryError
12-10 17:49:21.393: E/AndroidRuntime(16350): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-10 17:49:21.393: E/AndroidRuntime(16350): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
12-10 17:49:21.393: E/AndroidRuntime(16350): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:301)
12-10 17:49:21.393: E/AndroidRuntime(16350): at com.smalt.photoview.MyAdapter.getView(MyAdapter.java:110)
我的Android類文件這樣寫:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
if (convertView == null) {
convertView = inflater.inflate(R.layout.item, null);
viewHolder = new ViewHolder();
viewHolder.imageView = (ImageView) convertView
.findViewById(R.id.item_imageview);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeFile(
imgPathlist.get(position % imgPathlist.size()), options);
viewHolder.imageView.setImageBitmap(bitmap);// 爲ImageView設置內容
viewHolder.imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
viewHolder.imageView.setLayoutParams(new LinearLayout.LayoutParams(
100, 100));
viewHolder.imageView.setBackgroundResource(mGalleryItemBackground);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
return convertView;
}
class ViewHolder {
ImageView imageView;
}
我不知道如何解決的代碼,請教我該怎麼辦?