我有一个imageAdapter 这是代码:
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageGalleryAdapter extends BaseAdapter {
private Context mContext;
public String[] imagePaths;
public ImageGalleryAdapter(Context c, String paths) {
mContext = c;
imagePaths = paths.split(";");
}
@Override
public int getCount() {
return imagePaths.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return imagePaths[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("IMAGE GALLERY ADAPTER", ""+position);
ImageView imageView = new ImageView(mContext);
imageView.setImageURI(Uri.parse(imagePaths[position]));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
我不知道为什么,但它总是让我的应用程序没有响应,所以我尝试设置Log.i来检查getView中的位置,结果是位置总是有值= 0,而imagePath.length = 4。
为什么这总是卡在位置= 0
这是日志:
07-11 18:38:25.310: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:25.313: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:59
07-11 18:38:25.316: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:25.316: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:25.484: I/dalvikvm-heap(32154): Grow heap (frag case) to 29.849MB for 19660816-byte allocation
07-11 18:38:25.726: I/SurfaceTextureClient(32154): [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
07-11 18:38:25.744: E/MMUMapper(32154): fail to register MVA, unsupported format(0x5)
07-11 18:38:25.746: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:25.749: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:60
07-11 18:38:25.751: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:25.751: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:25.943: I/dalvikvm-heap(32154): Grow heap (frag case) to 48.574MB for 19660816-byte allocation
07-11 18:38:26.191: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:26.194: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:60
07-11 18:38:26.195: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:26.195: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:26.214: I/dalvikvm-heap(32154): Forcing collection of SoftReferences for 19660816-byte allocation
07-11 18:38:26.243: E/dalvikvm-heap(32154): Out of memory on a 19660816-byte allocation.
请帮助解决这个问题
答案 0 :(得分:2)
好像你的位图导致内存不足而没有被添加,尝试重新采样图像更小
Out of memory on a 19660816-byte allocation.
你甚至把这个项目添加到字符串数组中吗?