G
Garnet
Ambitioniertes Mitglied
Hallo,
ich würde gerne meine ListView mit Bildern füllen, deren Pfad ich in einer Datenbank abgespeichert habe. Also in der Datenbank steht für ein Bild immer "drawable/bildname".
Ich habs mit folgendem Code versucht, bekomme da aber eine NullPointerException. :-(
Kann mir einer sagen, was ich da falsch mache? Hatte den gleichen Code an anderer Stelle mit einem einzelnen Bild versucht, da hatte es problemlos funktioniert.
[/LEFT]
ich würde gerne meine ListView mit Bildern füllen, deren Pfad ich in einer Datenbank abgespeichert habe. Also in der Datenbank steht für ein Bild immer "drawable/bildname".
Ich habs mit folgendem Code versucht, bekomme da aber eine NullPointerException. :-(
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]for[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i=1; i<=anzahl-1; i++) [/LEFT]
{
...
[/SIZE]
[SIZE=2]ImageView image = (ImageView) findViewById(R.id.
[/SIZE][LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]imageViewfoto[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]cur[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = DataBaseHelper.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]appDB2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].rawQuery([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SELECT Foto_ID "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"FROM Sprecher "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"WHERE _id = ? "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String[] {sprecherID});[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spaltenindex[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]cur[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnIndex([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Foto_ID"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]String fotoID = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]cur[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getCount() > 0)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]cur[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].moveToFirst();[/SIZE]
[SIZE=2]fotoID = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]cur[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getString([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spaltenindex[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][/LEFT]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] bild = getResources().getIdentifier([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + fotoID, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], getPackageName()); [/SIZE][/LEFT]
[SIZE=2]image.setImageResource(bild);[/SIZE]
[/LEFT]