I’m getting a NullPointerException when I try to set a listener on my rating bar
My ratingBar is inside a scrollView and above, outside this view there’s a videoView wich plays a video.
My code:
final RatingBar videoRating=(RatingBar)findViewById(R.id.ratingBarNews);
videoRating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar rBar, float fRating, boolean fromUser) {
Log.i("rate_news", fRating);
}
});
The exception is thrown at:
setOnRatingBarChangeListener
Is this because it’s inside a scrollView, I tried a lot but with no success.
Thanks in advance.
Make sure this code runs after your call to
setContentView(). If you do it before that, findViewById will return null. If this is already after the call tosetContentView, make sure your layout specified in that call actually contains the view with that id.