The getter and setter class is becoming NULL when i try to fetch values form it.
in the code below, plz read the comments, i have added, for the explanation.
i have spent too much time on it and not getting whats the problem there… I m struck !!
I jst want to get the CategoryID and File and append them to the URL to show thumbnails on each row of my ListView.
I have done changes many times but not working…
public class MySimpleArrayAdapter extends ArrayAdapter<String>
{
////** Create Object For SiteList Class */
SitesList sitesList = null; //////// This is my Custom SitesList Class that contains ArrayLists
public Context context;
public ArrayList<String> siteslist;
public MySimpleArrayAdapter(Context context, ArrayList<String> siteslist)
{
super(context, R.layout.row, R.id.tv_label, siteslist);
this.context = context;
this.siteslist = siteslist; //////// Uptill here, the Siteslist is picking all desired values and storing in it
}
public View getView(int position, View convertView ,ViewGroup parent)
{
View v = convertView;
if(v == null)
{
LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v= inflator.inflate(R.layout.row, null);
}
TextView tv_name = (TextView) v.findViewById(R.id.tv_label);
tv_name.setText(siteslist.get(position));
ImageView thumbnail = (ImageView) v.findViewById(R.id.iv_left);
//////// But here the sitesList becomes **NULL**
String categoryid = sitesList.getcategoryid().get(position).toString();
final String url = "http://dev.takkekort.no/page/designer/masks/" + categoryid +"/front/landscape/" + file ;
////////////// I want to use the above String url in the GetImage Class below to fetch each image and show it as a thumbnail in the listview.
new GetImage(url).execute(thumbnail);
return v;
}
}
And here is my SitesList Class which contains getter ans setter methods
/** Contains getter and setter method for varialbles */
public class SitesList
{
/** Variables */
public ArrayList<String> categoryid = new ArrayList<String>();
/**
* In Setter method default it will return arraylist change that to add
*/
public ArrayList<String> getcategoryid() ////////// Category ID
{
return categoryid;
}
public void setcategoryid(String categoryid)
{
this.categoryid.add(categoryid);
}
}
Kindly update my code if possible.
Thanks in advance !!!
As pointed out in another answer, you’ve got two different variables that differ only in the case of a single letter – sitesList vs siteslist. This is valid in Java, but a very bad idea. It’s already confused most of the answerers and yourself as well.
Start by removing the one you don’t want to use or, if both are needed, rename one of them to a more distinct name and I think it’ll become more clear where your problem is.
You set sitesList (capital ‘L’) here:
And don’t do anything else with it until here:
It didn’t become
null, it was never anything else. Now you are also doing something with another object named siteslist (lower-case ‘L’), which is where your confusion is occurring.