getter和setter類中獲得價值正在成爲空當我嘗試獲取值形成的。 在下面的代碼中,PLZ閱讀了註釋,我已經添加了解釋。 我花了太多時間在它上面,沒有得到最新的問題......我被擊中了! 我想獲得CategoryID和文件,並將它們附加到URL以在我的ListView的每一行上顯示縮略圖。 我已經做了修改很多次,但沒有工作...空指針Expetion從
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;
}
}
這裏是我的SitesList類,它包含的getter ANS setter方法
/** 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);
}
}
如果可能的話請更新我的代碼。
在此先感謝!
是喲,你肯定getcategoryid()是ArrayList的的方法是什麼? –
Maep
是的,我已經在我的Siteslist班組長加入這種方法 公衆的ArrayList getcategoryid()\t //////////類別ID \t { \t \t回類別ID; \t} –
Noman