Nullpointer bei Ratingbar

S

spike78

Neues Mitglied
0
Moin zusammen,

seit gestern Abend kämpfe ich mit meiner Ratingbar rum. Ich hoffe mal ihr könnt mir weiterhelfen.

Ich habe in meiner Liste eine Ratingbar drin:

Code:
[LEFT][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]RatingBar[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:id[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@+id/rb_main_rating"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:layout_width[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"wrap_content"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:layout_height[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"wrap_content"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:numStars[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"3"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:layout_marginTop[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"2dip"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]style[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"?android:attr/ratingBarStyleSmall"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]RatingBar[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE]

Meine Liste wird mit DB Inhalten aufgebaut. Das funktioniert auch alles soweit. Das mache ich mit:
setViewValue(View view, Cursor theCursor, int column)

Aber sobald ich an die Stelle komme an der die Ratingbar befüllt werden soll, knallts:

Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]rb_main_[COLOR=#2a00ff]rating[/COLOR][/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]:[/SIZE][/LEFT]
 
[SIZE=2]RatingBar rb = (RatingBar) view.findViewById(R.id.[/SIZE]
[LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]rb_main_[COLOR=#2a00ff]rating[/COLOR][/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]

[SIZE=2]rb.setRating(1); // Hier fliegt ne Nullpointer[/SIZE][/LEFT]

 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE][/LEFT]

Hier noch die Exception:
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): FATAL EXCEPTION: main
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): java.lang.NullPointerException
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): at de.androiddev.testapp.Testliste$1.setViewValue(Testliste.java:135)
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:126)
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): at android.widget.CursorAdapter.getView(CursorAdapter.java:186)
12-01 11:21:00.159: ERROR/AndroidRuntime(4122): at​

Danke und Gruß​

Spike​
 
Hi spike78,

jo, stimmt.

rb ist null und es gibt eine NullPointException.

Hast du auch Fragen dazu?

regards
 
Sowas passiert gerne, wenn man findViewById irrtümlicher Weise vor setContentView aufruft.
 
  • Danke
Reaktionen: spike78
Das wars. Vielen Dank
 

Ähnliche Themen

D
Antworten
17
Aufrufe
324
datNeMo
D
Y
Antworten
4
Aufrufe
1.188
swa00
swa00
R
  • RudolfHagen
Antworten
1
Aufrufe
637
koje71
koje71
Zurück
Oben Unten