如何将字符串项添加到列表?

时间:2015-08-09 22:37:30

标签: android arrays list

我收到错误:

  

Girl中的Girl(String,String)无法应用于(String)

这是我的代码:

package com.herprogramacion.toolbarapp;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;


public class Girls {

public static final String[] girlsNamesDummy = {
        "Catherine", "Evelyn", "Phyllis", "Beverly", "Michelle",
        "Denise", "Virginia", "Ruth", "Barbara"
};


public static List<Girl> ctrl(int count) {

   List<Girl> items = new ArrayList<>();




    for (int im = 0; im < count; im ++) {

        items.add(new Girl(girlsNamesDummy[im]));

    }

    return new ArrayList<>(items);
}}

这里提供了girl.class和完整的代码。

public class Girl {

    private String name;
    private String yazi;
    private int idDrawable;

    public Girl(String name, String yazi) {
        this.name = name;
        this.idDrawable = getDrawable();
        this.yazi = yazi;
    }


    public String getName() {
        return name;
    }

    public int getIdDrawable() {
        return idDrawable;
    }


    private int getDrawable() {

        switch (idDrawable) {
            default:
            case 0:
                return R.drawable.girl1;
            case 1:
                return R.drawable.girl2;
            case 2:
                return R.drawable.girl3;
            case 3:
                return R.drawable.girl4;
            case 4:
                return R.drawable.girl5;
            case 5:
                return R.drawable.girl6;
            case 6:
                return R.drawable.girl7;
            case 7:
                return R.drawable.girl8;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

你应该发布Girl课程。从我可以说你有构造函数的问题。如果您定义了2个参数构造函数(String,String),并且您尝试使用此调用调用1参数构造函数(String):

  

新女孩(girlsNamesDummy [im])