Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的背景是什么?我在哪里找到它?_Java_Android_Universal Image Loader - Fatal编程技术网

Java 我的背景是什么?我在哪里找到它?

Java 我的背景是什么?我在哪里找到它?,java,android,universal-image-loader,Java,Android,Universal Image Loader,我之前问过一个类似的问题,但我不知道该怎么办,我还读过其他解决方案,如: 我仍然不知道该怎么办,请帮助: 据我所知,我的上下文=null;我不知道为什么,以及如何修复它 我编写了一个UniversImageLoader.class,以便能够在多个活动中加载图像。现在我已经在我的所有活动中启动了它,但是在我的UIL类中,我需要传递一个上下文 public class UniversalImageLoader { private static final int defaultImage

我之前问过一个类似的问题,但我不知道该怎么办,我还读过其他解决方案,如: 我仍然不知道该怎么办,请帮助:

据我所知,我的上下文=null;我不知道为什么,以及如何修复它

我编写了一个UniversImageLoader.class,以便能够在多个活动中加载图像。现在我已经在我的所有活动中启动了它,但是在我的UIL类中,我需要传递一个上下文

public class UniversalImageLoader {

    private static final int defaultImage = R.drawable.ic_android;
    private Context mContext;

    public UniversalImageLoader(Context context) {
        mContext = context;
    }

    public ImageLoaderConfiguration getConfig(){
        //File cacheDir = StorageUtils.getCacheDirectory(mContext);
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)//<--the error is in this line
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                .diskCacheExtraOptions(480, 800, null)
                .threadPriority(Thread.NORM_PRIORITY - 2) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(mContext)) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs()
                .build();

        return config;
    }
在所有这些活动中,我在OnCreate方法中将其称为:

initImageLoader();
因此,我已经阅读了其他解决方案,但找不到一个可以理解的答案……非常感谢您的指导

使用this.mContext=context;在构造函数中,它将把您的上下文传递给当前类的上下文

并将getApplicationContext或yourActivityName.this传递给正在使用此类的位置


如果您在片段中使用它,请使用getActivity或getContext。

只需将其作为参数传递,而不是在活动中传递mContext。新的通用图像加载程序;错误:无法将UniversalImageLoader中的UniversalImageLoader android.content.Context应用于activityOk。如果您在片段中,则需要传递requireContext。新的UniversalImageLoaderRequestRecontext在这个特定的上下文中,如果他使用getApplicationContext并将类转换成一个单例,考虑到它将被用于多个活动,这不是更好吗?@darius f。。。非常感谢我所需要的。。。
initImageLoader();