-1

我正在尝试使用动态图像视图创建一个 viewflipper,图像视图的 src 来自 sd 卡路径。我想使用通用图像加载器库加载图像。将图像绑定到图像视图时出现空指针异常。

下面是我的代码

 private class someTask extends AsyncTask<Void, Void, Void> {

@Override
    protected Void doInBackground(Void... params) {

        getPages();
            return null;

    }

    @Override
    protected void onPostExecute(Void result) {
        setPageLocations();
        dismissProgress();
    }
}


 private void getPages()
{


     while(mCursor.moveToNext()){
         String pageLocation = get images from database;
                gallery_grid_Images[i] = pageLocation;

         i++;
     }
}

private void setPageLocations(){

    for (int i=0;i<gallery_grid_Images.length;i++){
        /* Bitmap bitmap = BitmapFactory.decodeFile(gallery_grid_Images[i]);
          BitmapDrawable bd = new BitmapDrawable(bitmap);
            ImageView imageView = new ImageView(getApplicationContext());
           imageView.setImageDrawable(bd);*/
   imageLoader.displayImage(gallery_grid_Images[i], imageView,options);

          viewFlipper.addView(imageView);
    }
}

任何帮助将不胜感激。指向使用通用图像加载器的 viewflipper 示例的链接也将有所帮助。

谢谢。

PS:它适用于注释代码。但由于有很多图像,我不想遇到内存不足错误。

下面是堆栈跟踪

03-17 02:37:16.852: E/AndroidRuntime(476): FATAL EXCEPTION: main
03-17 02:37:16.852: E/AndroidRuntime(476): java.lang.NullPointerException
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.nostra13.universalimageloader.core.ImageLoader.getImageSizeScaleTo(ImageLoader.java:453)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:214)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:153)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.sofi.magz.networkusage.MagzineReader.setPageLocations(MagzineReader.java:177)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.sofi.magz.networkusage.MagzineReader.access$1(MagzineReader.java:167)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.sofi.magz.networkusage.MagzineReader$SetMagzineReaderTask.onPostExecute(MagzineReader.java:119)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.sofi.magz.networkusage.MagzineReader$SetMagzineReaderTask.onPostExecute(MagzineReader.java:1)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.os.AsyncTask.finish(AsyncTask.java:417)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.os.Looper.loop(Looper.java:130)
03-17 02:37:16.852: E/AndroidRuntime(476):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-17 02:37:16.852: E/AndroidRuntime(476):  at java.lang.reflect.Method.invokeNative(Native Method)
03-17 02:37:16.852: E/AndroidRuntime(476):  at java.lang.reflect.Method.invoke(Method.java:507)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-17 02:37:16.852: E/AndroidRuntime(476):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-17 02:37:16.852: E/AndroidRuntime(476):  at dalvik.system.NativeStart.main(Native Method)

在 167 调用 setpagelocation。

4

3 回答 3

3

我通过在调用通用图像加载器的 displayImage 之前添加视图解决了上述错误。

于 2013-03-16T21:25:24.717 回答
0

设置它的LayoutParams,</p>

...

imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

imageLoader.displayImage(gallery_grid_Images[i], imageView,options); viewFlipper.addView(imageView);

...

于 2013-05-24T08:41:47.787 回答
0

在调用通用图像加载器的 displayImage 之前添加视图

于 2014-08-18T08:09:28.393 回答