Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建适配器映像时无法应用对象中的对象()_Android - Fatal编程技术网

Android 创建适配器映像时无法应用对象中的对象()

Android 创建适配器映像时无法应用对象中的对象(),android,Android,我正在创建适配器映像,出现以下2个错误: 这是密码 public class GridViewAdapter { private Context mcontext; private int layoutResourceId; public GridViewAdapter(Context context, int layoutResourceId, ArrayList<Listitem> listitem) { super(context,

我正在创建适配器映像,出现以下2个错误:

这是密码

public class GridViewAdapter {

    private Context mcontext;
    private int layoutResourceId;

    public GridViewAdapter(Context context, int layoutResourceId, ArrayList<Listitem> listitem) {
        super(context, layoutResourceId, listitem);
        this.layoutResourceId = layoutResourceId;
        this.mcontext =context;

    }

super
尝试调用
super类
。您没有扩展任何内容,因此隐式地继承了
对象
,而该对象又没有这样的构造函数(接受三个参数的构造函数)

改变

public class GridViewAdapter {

公共类GridViewAdapter扩展了ArrayAdapter{

正如我们所知,java中的super正在调用扩展类构造函数,而在您的例子中,它没有扩展类。
请记住,如果没有扩展类,超级调用对象类的无参数构造函数,并且对象类没有带三个参数的构造函数。

我认为@Blackbelt answer适合您。此外,您可以在需要时阅读下面的我的答案以供参考。谢了,我会检查的,也许您一点就忘了我的答案如果您以前的问题
公共类CustomGridViewAdapter Extendes ArrayAdapter
:)@BNK是的,谢谢您提醒我您的答案。我将再次查看。如果您希望将此作为另一个问题发布,我将发布,但我在调用适配器
GridViewAdapter=new GridViewAdapter时出错(此,R.layout.grid\u项目\u布局,Listitem)
错误出现在
这个
上。我添加了Mainactivity。这不起作用。我正在okhttp类中调用适配器。我应该用它替换什么?第一个参数是一个上下文对象。问问自己这是一个上下文吗?@Moudiz因为在asynctask类中使用了okhttp,所以不要使用“this”,您可以使用mContext=this,然后在适配器的构造函数中使用mContext,就像上面的“我的答案”链接一样,或者如果您在一个内部类中实例化它,而外部类是一个活动,那么您可以使用
NameActivity.this
。如果外部类是一个片段,则必须使用
getActivity()
@Blackbelt您能检查一下吗
public class GridViewAdapter {
public class GridViewAdapter extends ArrayAdapter<ListItem> {