Android SQLite getList问题

时间:2016-03-29 06:28:59

标签: android sqlite

大家好我是Android开发新手也许这是一个简单的问题,但我坚持下去,请帮忙。我的班级。我不能把Uretimyeri投射到弦上。我怎么能这样做。

    private String Oid;
    private String MalzemeGrubu;
    private String Musteri;
    private UretimYeriBean UretimYeri;
    private String Model;
    private Integer Tipi;
    private Integer Durum;
    private String OzelKod;
    private String Adi;
    private String Kodu;

UretimYeriBean是

private String Oid;
private Integer Tipi;
private Integer Durum;
private String OzelKod;
private String Adi;
private String Kodu;

这是我的获取列表功能。

 public List<MalzemeBean> getList() {

    List<MalzemeBean> liste = new ArrayList<MalzemeBean>();
    SQLiteDatabase db = Global.DB.getReadableDatabase();
    String selectQuery = "Select Oid,MalzemeGrubu,Musteri,UretimYeri,Model,Tipi,Durum,OzelKod,Adi,Kodu"
            + " FROM " + TABLE_NAME + " Order by Ad COLLATE UNICODE";

    Cursor c = db.rawQuery(selectQuery, null);
    if (c.moveToFirst()) {

        do {
            MalzemeBean mlz = new MalzemeBean();
            mlz.setOid(c.getString(c.getColumnIndex("Oid")));
            mlz.setMalzemeGrubu(c.getString(c.getColumnIndex("MalzemeGrubu")));
            mlz.setMusteri(c.getString(c.getColumnIndex("Musteri")));
            mlz.setUretimYeri(c.getString(c.getColumnIndex("UretimYeri")));
            mlz.setModel(c.getString(c.getColumnIndex("Model")));
            mlz.setTipi(c.getInt(c.getColumnIndex("Tipi")));
            mlz.setDurum(c.getInt(c.getColumnIndex("Durum")));
            mlz.setOzelKod(c.getString(c.getColumnIndex("OzelKod")));
            mlz.setAdi(c.getString(c.getColumnIndex("Adi")));
            mlz.setKodu(c.getString(c.getColumnIndex("Kodu")));
            liste.add(mlz);
        } while (c.moveToNext());
    }
    c.close();
    return liste;
}


givets给我错误

mlz.setUretimYeri(c.getString(c.getColumnIndex("UretimYeri"))); 

行,并说:

  

错误:(57,56)错误:不兼容的类型:无法转换字符串   到UretimYeriBean。那么我如何将Uretimyeri.Oid转换为字符串

1 个答案:

答案 0 :(得分:1)

实际上您需要将UretimYeriBean Object设置为mlz.setUretimYeri(.....)

您正试图设置String这是错误的

mlz.setUretimYeri(c.getString(c.getColumnIndex("UretimYeri")));

正确的方法是

mlz.setUretimYeri(new UretimYeriBean(Oid,Tipi,Durum,OzelKod,Adi,Kodu));