从BaseAdapter访问活动变量

时间:2015-07-02 00:40:05

标签: java android baseadapter

我想从BaseAdapter班级的活动中访问变量,并与我一起设置活动的ListView。 但我总是得到这个错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Integer.toString()' on a null object reference

这些是我的代码的相关部分:

public class GetAllEntrysListViewAdapter extends BaseAdapter {

Integer markerID;
PinboardActivity pinboard = new PinboardActivity();

public GetAllEntrysListViewAdapter(JSONArray jsonArray, Context context) {
    this.dataArray = jsonArray;
    this.context= context;
    //I want to get the markerID variable from pinboardActivity:
    markerID = pinboard.markerID;
    inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
//...
public Cursor getLikes(DbHelper dbh) {
    //The following line is the one the error occurs
    String args[] = {markerID.toString(), pos};
    //...
}

1 个答案:

答案 0 :(得分:0)

这是因为markerIDnull 检查以下行

//I want to get the markerID variable from pinboardActivity:
    markerID = pinboard.markerID;

这里pinboard.markerID返回一个空对象。