错误: 无法将类 Person中的构造器 Person应用到给定类型; 需要: 没有参数 找到: int,String,int 原因: 实际参数列表和形式参数列表长度不同

Person

public class Person {
    private int  _id;
    private String name;
    private int age;
    Person(int _id, String name, int age) {
        this._id = _id;
        this.name = name;
        this.age = age;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public int get_id(){
        return _id;
    }
    public String getName() {
        return name;
    }
    public int getAge() {
        return age;
    }

main avtivity

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
     MyDAO myDAO;
     ListView listView;
     ListlistData;
     BaseAdapter adapter;
     int selId;
     EditText et_name;
     EditText et_age;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button bt_add=findViewById(R.id.bt_add);bt_add.setOnClickListener(this);
        Button bt_modify=findViewById(R.id.bt_modify);bt_modify.setOnClickListener(this);
        Button bt_del=findViewById(R.id.bt_del);bt_del.setOnClickListener(this);
        et_name=findViewById(R.id.et_name);
        et_age= findViewById(R.id.et_age);
        myDAO=new MyDAO(this);
        if(myDAO.getRecordsNumber()==0){
            myDAO.insertInfo("tian",20);
            myDAO.insertInfo("wang",40);
        }
        displayRecords();
    }
    public void displayRecords(){
        listView=findViewById(R.id.listView);
        listData=new ArrayList();
        Cursor cursor=myDAO.allQuery();
        while (cursor.moveToNext()){
            int id=cursor.getInt(0);
            String name=cursor.getString(1);
            int age=cursor.getInt(cursor.getColumnIndex("age"));
            Person person=new Person(id,name,age);
            listData.add(person);
        }
adapter=new BaseAdapter() {
    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = 28)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       View item=View.inflate(getApplicationContext(),R.layout.list_item,null);
        TextView idTV=item.findViewById(R.id.tv_id);
        TextView nameTV=item.findViewById(R.id.tvname);
        TextView ageTV=item.findViewById(R.id.tvage);
        Person p=listData.get(position);
        idTV.setText(p.get_id()+"");
        nameTV.setText(p.getName());
        ageTV.setText(p.getAge()+"");
        return item;
    }
};
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @RequiresApi(api = 28)
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        Person rec=(Person)adapter.getItem(position);
        et_name.setText(rec.getName());
        et_age.setText(rec.getAge()+"");
        selId=rec.get_id();
    }
});
    }
    @Override
    public void onClick(View v){
        if(selId>0){
            String p1 =et_name.getText().toString().trim();
            int p2=Integer.parseInt(et_age.getText().toString());
            switch (v.getId()){
                case R.id.bt_add:
                    myDAO.insertInfo(p1,p2);
                    break;
                case R.id.bt_modify:
                    myDAO.updateInfo(p1,p2,selId);
                    Toast.makeText(getApplicationContext(),"更新成功!",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.bt_del:
                    myDAO.deleteInfo(selId);
                    Toast.makeText(getApplicationContext(),"删除成功!",Toast.LENGTH_SHORT).show();
                    et_name.setText(null);et_age.setText(null);selId=0;
            }

        }else {
            if(v.getId()==R.id.bt_add){
                String p1=et_name.getText().toString();
                String p2=et_age.getText().toString();
                if(p1.equals("")||p2.equals("")){
                    Toast.makeText(getApplicationContext(),"姓名和年龄都不能空!",Toast.LENGTH_SHORT).show();
                }else {
                    myDAO.insertInfo(p1,Integer.parseInt(p2));
                }
            }else {
                Toast.makeText(getApplicationContext(),"请先选择记录!",Toast.LENGTH_SHORT).show();
            }
        }
        displayRecords();
    }
}



Person(int _id, String name, int age) {
->
public Person(int _id, String name, int age) {
否则构造函数是私有的了

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 以下回答来自chatgpt:

    这个问题的原因是在调用 Person 类的构造函数时缺少参数,可以按照以下步骤解决:

    1. 确认 Person 类的构造函数是否需要参数。如果需要,则需要提供正确的参数类型和数量。
    2. 如果 Person 类的构造函数不需要参数,则检查是否在调用该构造函数时不小心传递了参数。如果有,请将其删除。
    3. 确认在调用 Person 类的构造函数时使用了正确的语法。例如,如果在 Java 中调用构造函数,应使用 "new" 关键字来创建对象,并在括号中提供参数,如下所示:
    Person person = new Person(name, age);
    

    其中 "name" 和 "age" 是 Person 类构造函数需要的参数。如果没有参数,则不需要在括号中添加参数列表。

    1. 如果问题仍然存在,请检查构造函数声明是否与调用的语法匹配。例如,如果构造函数声明为:
    public Person(String name, int age) {
        // constructor code
    }
    

    则应使用如下语法调用:

    Person person = new Person("John Smith", 25);
    

    即传递类型和数量正确的参数。

    1. 如果所有上述步骤都无法解决问题,则可能是代码其他部分引起的问题,需要进一步检查代码。

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^