【问题标题】:ImageLoader NullPointerException [duplicate]ImageLoader NullPointerException [重复]
【发布时间】:2017-01-22 14:16:37
【问题描述】:

当我尝试获取位图时,我收到了一个空指针表达式。

ImageLoader imageLoader = ImageLoader.getInstance();
Bitmap bmp = null;
bmp = imageLoader.loadImageSync("http://i.imgur.com/tx41HBE.jpg");

调用imageLoader.loadImageSync()方法后bmp变量为null,是什么原因?

【问题讨论】:

    标签: android gradle nullpointerexception android-bitmap imageloader


    【解决方案1】:

    试试这个

    private ImageLoader imageLoader;
      private ImageLoaderConfiguration config;
    config = new ImageLoaderConfiguration.Builder(this)
        .threadPriority(Thread.NORM_PRIORITY - 2)
        .denyCacheImageMultipleSizesInMemory()
        .diskCacheFileNameGenerator(new Md5FileNameGenerator())
        .diskCacheSize(50 * 1024 * 1024) // 50 Mb
        .tasksProcessingOrder(QueueProcessingType.LIFO)
        .writeDebugLogs() // Remove for release app
        .build();
    imageLoader =  ImageLoader.getInstance();
    imageLoader.init(config);
    Bitmap bmp = null;
                        bmp = imageLoader.loadImageSync("http://i.imgur.com/tx41HBE.jpg");
    

    原因可能是您没有使用 imageLoader.init(config)

    初始化 imageLoader

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2022-01-05
      相关资源
      最近更新 更多