0

I am trying to load some images from the array and the following is my schedule adapter. Just getting undefined context. Not sure what to do ? Also no images are being loaded

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();
Sam
  • 350
  • 5
  • 18

1 Answers1

3

Simply use activity.getApplicationContext() instead of getApplicationContext()

Your current class inherits from ArrayAdapter, which is not a subclass of Context. The getApplicationContext() method is only available in classes inheriting from Context, like Activities, Services and BroadcastReceivers.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • When I use activity.getApplicationContext() , it says the blank field may have not been initalized. It is referring to Activity activity. And asking me to remove the final . So from private final Activity activity; to private Activity activity; – Sam May 19 '13 at 03:13
  • @Sam You will have to remove final. When you declare something as final, it means you cannot alter the value after its creation, so it won't get assigned. – Raghav Sood May 19 '13 at 03:14
  • Removing Final gives me a null pointer exception on that line. I think that though might be altogether a different problem. – Sam May 19 '13 at 03:16
  • Are you sure you're receiving a valid Activity instance? – Raghav Sood May 19 '13 at 03:18
  • yes it is receiving a Valid activity instance. I think there is some issue with my code that should set the images in the adapter. – Sam May 19 '13 at 03:21
  • I have updated the full code above can you have a look please ? – Sam May 19 '13 at 03:21
  • Post the code where you create and use an instance of `Schedule_ArrayAdapter` – Raghav Sood May 19 '13 at 03:23
  • ok I have updated the secondary code. You can see how I use the adapter after fetching the JSON values. – Sam May 19 '13 at 03:28
  • here is the pastbin http://pastebin.com/aXjW15GC. The line is 26 in Schedule_Arrayadapter – Sam May 19 '13 at 03:35
  • added the xml as well for you to have a look. – Sam May 19 '13 at 03:36
  • Thanks for the help anyways. If it too much to ask I might open another thread about this. – Sam May 19 '13 at 03:45
  • @Sam hmm. I can't see anything wrong here. You might have better luck with someone else if you open another thread though – Raghav Sood May 19 '13 at 03:53