Universal Image Gallery上的getApplicationContext()是未定义的?

时间:2013-05-19 03:09:57

标签: android universal-image-loader

我正在尝试从阵列加载一些图像,以下是我的日程安排适配器。 只是得到未定义的上下文。不知道该怎么办 ? 也没有加载图像

public class Schedule_ArrayAdapter extends ArrayAdapter<String> {
private final Activity activity;
private final String[] name, category, image;
Typeface colab, colab_bold, Bebas;
int selected = -1;

public Schedule_ArrayAdapter(Activity activity, String[] name, String[] category, String[] image) {
    super(activity, R.layout.schedule_item, category);
    this.activity = activity;
    this.name = name;
    this.category = category;
    this.image = image;

    this.colab = Typeface.createFromAsset(activity.getAssets(), "ColabThi.otf");
    this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "ColabMed.otf");
    this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "BebasNeue.otf");
//  ImageLoader.getInstance().init(config);
    imageLoader = ImageLoader.getInstance();
}

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    .memoryCache(new WeakMemoryCache())
    .denyCacheImageMultipleSizesInMemory()
    .threadPoolSize(5)
    .enableLogging()
    .build();

    DisplayImageOptions options = new DisplayImageOptions.Builder()
    .cacheOnDisc()
    .cacheInMemory()
    .build();

    ImageLoader imageLoader= ImageLoader.getInstance();

1 个答案:

答案 0 :(得分:3)

只需使用activity.getApplicationContext()代替getApplicationContext()

您当前的类继承自ArrayAdapter,它不是Context的子类。 getApplicationContext()方法仅适用于继承自Context的类,例如ActivitiesServicesBroadcastReceivers