我想从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};
//...
}
答案 0 :(得分:0)
这是因为markerID
是null
检查以下行
//I want to get the markerID variable from pinboardActivity:
markerID = pinboard.markerID;
这里pinboard.markerID
返回一个空对象。