Universal Image Loaderを使用してグリッドビューに画像を設定しようとすると、nullpointer例外が発生します。クラッシュは、最初のイメージがダウンロードされたときに発生し、アプリケーションがクラッシュする前に1つのイメージがダウンロードされます。(httpscoopで確認)
編集:これは間違っています。クラッシュは最初のイメージがダウンロードされる前に発生するため、存在しないイメージを測定しようとする可能性があります。
これは私のグリッドアイテムです
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/gridImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/gallery_grid_image_desc"/>
グリッドビューのレイアウトは単なるグリッドビューです
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/galleryPicturesGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:verticalSpacing="@dimen/gallery_grid_spacing"
android:horizontalSpacing="@dimen/gallery_grid_spacing"
android:numColumns="3" />
私のgetView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder = null;
Log.d(TAG, "getView " + position);
if (view == null) {
view = ((Activity) context).getLayoutInflater().inflate(
R.layout.gallery_grid_item, null);
holder = new ViewHolder();
holder.thumb = (ImageView) view.findViewById(R.id.gridImageView);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Picture picture = mPictures.valueAt(position);
mImageLoader.displayImage(picture.getThumbUrl(), holder.thumb, mImageOptions);
return null;
}
ImageLoaderの構成
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext()).memoryCacheSize(2 * 1024 * 1024)
.discCache(new UnlimitedDiscCache(cacheDir))
.denyCacheImageMultipleSizesInMemory()
.offOutOfMemoryHandling()
.threadPoolSize(4)
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
.tasksProcessingOrder(QueueProcessingType.LIFO)
.imageDownloader(new UrlConnectionImageDownloader(this))
.build();
およびオプション
galleryThumbImageOptions = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.p1_cover)
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
と例外
01-18 10:56:15.434: E/AndroidRuntime(4089): FATAL EXCEPTION: main
01-18 10:56:15.434: E/AndroidRuntime(4089): java.lang.NullPointerException
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.GridView.onMeasure(GridView.java:937)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.View.measure(View.java:8313)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.os.Looper.loop(Looper.java:123)
01-18 10:56:15.434: E/AndroidRuntime(4089): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-18 10:56:15.434: E/AndroidRuntime(4089): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 10:56:15.434: E/AndroidRuntime(4089): at java.lang.reflect.Method.invoke(Method.java:507)
01-18 10:56:15.434: E/AndroidRuntime(4089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-18 10:56:15.434: E/AndroidRuntime(4089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-18 10:56:15.434: E/AndroidRuntime(4089): at dalvik.system.NativeStart.main(Native Method)