Java 当我尝试实例化自定义适配器时,为什么它不工作?

Java 当我尝试实例化自定义适配器时,为什么它不工作?,java,android,instantiation,Java,Android,Instantiation,我一直试图让这个自定义适配器工作,但由于某些原因,它没有。我试图创建一个名为ItemAdapter的新适配器,但它说当鼠标悬停在“ItemAdapter”上时,符号无法解析。它说,ItemAdapter构造函数从未被使用过,即使我试图调用构造函数。你知道为什么吗 食物链接 public class FoodDrinks extends AppCompatActivity { @Override protected void onCreate(Bundle savedIn

我一直试图让这个自定义适配器工作,但由于某些原因,它没有。我试图创建一个名为
ItemAdapter
的新适配器,但它说当鼠标悬停在“ItemAdapter”上时,符号无法解析。它说,
ItemAdapter
构造函数从未被使用过,即使我试图调用构造函数。你知道为什么吗

食物链接

    public class FoodDrinks extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewitem);

        //create new array list to hold food and drink items
        ArrayList<NewItem> obj = new ArrayList<>();

        //add new items to array
        obj.add(new NewItem("Name", "Description", R.mipmap.ic_launcher));
        obj.add(new NewItem("Name", "Description", R.mipmap.ic_launcher));
        obj.add(new NewItem("Name", "Description", R.mipmap.ic_launcher));
        obj.add(new NewItem("Name", "Description", R.mipmap.ic_launcher));
        obj.add(new NewItem("Name", "Description", R.mipmap.ic_launcher));
        ItemAdapter adapter = new ItemAdapter(this, obj, R.mipmap.ic_launcher);
        ListView listview = (ListView) findViewById(R.id.l1);
        listview.setAdapter(adapter);
    }
}
公共类FoodLink扩展了AppCompative活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewitem);
//创建新数组列表以保存食物和饮料项
ArrayList obj=新的ArrayList();
//向数组中添加新项
添加(新的NewItem(“名称”、“说明”,R.mipmap.ic_启动器));
添加(新的NewItem(“名称”、“说明”,R.mipmap.ic_启动器));
添加(新的NewItem(“名称”、“说明”,R.mipmap.ic_启动器));
添加(新的NewItem(“名称”、“说明”,R.mipmap.ic_启动器));
添加(新的NewItem(“名称”、“说明”,R.mipmap.ic_启动器));
ItemAdapter=新的ItemAdapter(this,obj,R.mipmap.ic_启动器);
ListView ListView=(ListView)findViewById(R.id.l1);
setAdapter(适配器);
}
}
项目适配器

public class ItemAdapter extends ArrayAdapter<NewItem> {
private int mImageResource;
private ArrayList<NewItem> obj;

    public ItemAdapter(Context context, ArrayList<NewItem> obj, int imageResource) {
        super(context, 0, obj);
        mImageResource = imageResource;
        this.obj = obj;

    }
公共类ItemAdapter扩展了ArrayAdapter{
私有图像资源;
私人ArrayList obj;
公共项适配器(上下文上下文、ArrayList obj、int imageResource){
super(上下文,0,obj);
mimagerource=图像资源;
this.obj=obj;
}

导入FoodLink活动中的项目适配器类Display full
ItemAdapter
如果可能的话,这样我们就可以给出正确的解决方案。出于某种原因,我将ItemAdapter类放在了错误的文件夹中。在尝试导入时意识到了这一点。非常简单!谢谢!导入FoodLink活动中的项目适配器类Display full
ItemAdapter类,如果可能的话,这样我们就可以给出正确的解决方案。出于某种原因,我将itemadapter类放在了错误的文件夹中。在尝试导入它时意识到了这一点。非常简单!谢谢!