Buonsera. Premetto che non voglio la pappa pronta, dato che non sono proprio il tipo, e comunque meglio non offendere le persone che non si conoscono nemmeno dandogli del colui che vuole la pappa pronta....chi ha occhi per intendere intenda...dato che si deve leggere....
vabbè dopo questa breve introduzione....
ho un problemino...sto cercando di tirare fuori dal mio db tutte le info contenute in una tabellla (prodotti) del mio database.
Le informazioni le voglio salvare in un ArrayList personalizzato che fa riferimento a questa classe:
public class MyArt {
private String ARTICOLO;
private String URI;
private String ID_ARTICOLO;
private boolean NONCIBO;
private boolean CHANGED;
public String getId() {
return ID_ARTICOLO;
}
public void setId(String ID_ARTICOLO) {
this.ID_ARTICOLO = ID_ARTICOLO;
}
public String getArti() {
return ARTICOLO;
}
public void setArti(String ARTICOLO) {
this.ARTICOLO = ARTICOLO;
}
public String getUri() {
return URI;
}
public void setUri(String URI) {
this.URI = URI;
}
public void setNonCibo(boolean NONCIBO)
{
this.NONCIBO = NONCIBO;
}
public boolean getNonCibo ()
{
return NONCIBO;
}
public void setChanged(boolean CHANGED)
{
this.CHANGED = CHANGED;
}
public boolean getChanged ()
{
return CHANGED;
}
@Override
public String toString() {
return "[ID=" + ID_ARTICOLO + " AR=" + ARTICOLO + " QTA=" + URI + "]" + "\n";
}
}Per tirare fuori le informazioni mi sono creato il metodo:
public ArrayList<MyArt> selectArticoli() {
try {
ArrayList<MyArt> results = new ArrayList<MyArt>();
Cursor c = mDb.rawQuery("select * from prodotti", null);
if (c.getCount() > 0) {
c.moveToFirst();
do {
MyArt newArt=new MyArt();
newArt.setId(c.getString(c.getColumnIndex("IDAR")));
newArt.setArti(c.getString(c.getColumnIndex("NOMEAR")));
newArt.setUri(c.getString(c.getColumnIndex("URIIMGAR")));
newArt.setNonCibo(Boolean.parseBoolean(c.getString(c.getColumnIndex("NONCIBOAR"))));
newArt.setChanged(Boolean.parseBoolean(c.getString(c.getColumnIndex("CHANGEDAR"))));
results.add(newArt);
} while(c.moveToNext());
}
return results;
} finally {
// if (mDb != null)
//mDb.close();
}
} Dove i campi IDAR, NOMEAR, URIIMGAR, NONCIBOAR, CHANGEDAR sono i campi che vado a leggere a ogni iterazione nella tabella articoli andando poi a settare i rispettivi campi di ogni singolo elemento dell'arraylist.
Ora per richiamare il metodo faccio:
ArrayList<MyArt> result = db2.selectArticoli();
for(int j=0;j<result.size();j++)
Log.i("CIAOOOO",result.get(j).getId()+result.get(j).getArti()+result.get(j).getUri());Dove nel LogCat vado a far stampare quanto scritto nell'arraylist di ritorno dal metodo.
L'applicazione va in crash e nel logcat ho un errore che non riesco bene a comprendere:
11-01 20:24:50.440: ERROR/CursorWindow(402): Bad request for field slot 0,-1. numRows = 14, numColumns = 6
11-01 20:24:50.460: ERROR/AndroidRuntime(402): FATAL EXCEPTION: main
11-01 20:24:50.460: ERROR/AndroidRuntime(402): java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.egsolutions.databasetutorial/ch.egsolutions.databasetutorial.Demo}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
11-01 20:24:50.460: ERROR/AndroidRuntime(402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
..........
11-01 20:24:50.460: ERROR/AndroidRuntime(402): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
11-01 20:24:50.460: ERROR/AndroidRuntime(402): at android.database.CursorWindow.getString_native(Native Method)
Grazie per il supporto
Ciao a tutti.