gpt4 book ai didi

java - 从 BaseAdapter 访问 Activity 的变量

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:55 25 4
gpt4 key购买 nike

我想从 BaseAdapter 类中的 Activity 访问变量,我用该类设置了 Activity 的 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};
//...
}

最佳答案

这是因为 markerIDnull
检查您的以下行

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

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

关于java - 从 BaseAdapter 访问 Activity 的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31173868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com