I have a class named ItemsAdapter where I have three arguments and I am instantiating this class in another class named ItemsActivity.While doing so, I need to put up all the three arguments and the last argument is where I am gonna pass a method known as getImages() which is in the same class ItemsAdapter. I can access this only by using the ItemsAdapter object but it's not feasible. This is what I have tried :
CODE :
ItemsAdapter mAdapter = null;
ArrayList<String> image_items = mAdapter.getImages();
mAdapter = new ItemsAdapter(this,R.layout.item,image_items);
UPDATE :
public ArrayList<String> getImages()
{
String path = android.os.Environment.getExternalStorageDirectory() + "/Pictures/SanPics2/";
File mainfolder = new File(path);
ArrayList<String> files = new ArrayList<String>();
if(mainfolder.listFiles() == null)
return null;
for(File f : mainfolder.listFiles())
{
if(f.getName().contains(".jpg"))
{
files.add(f.getAbsolutePath());
}
}
return files;
}
This is the method which I am trying to access. It throws NullPointerException as predicted. Is there a another way around this where I can access the method getImages() in ItemsAdapter class. Apologies if the question is dumb(i know it is) but I am just a beginner to programming and stuffs. Any idea on how to achieve this would be highly appreciated. Thanks in advance.
getImages?. What does it return?