Help with getParent() downcast.

Posted by Preformed Cone on Stack Overflow See other posts from Stack Overflow or by Preformed Cone
Published on 2010-04-28T02:54:11Z Indexed on 2010/04/28 3:03 UTC
Read the original article Hit count: 184

Filed under:

I'm learning android/java and have this example code I can't get to work:

OnRatingBarChangeListener l = new OnRatingBarChangeListener() {
 public void onRatingChanged(RatingBar ratingBar, float rating,
   boolean fromTouch) {
  Integer myPos=(Integer)ratingBar.getTag();
  RowModel model=getModel(myPos);
  model.rating = rating;

  LinearLayout p=(LinearLayout)ratingBar.getParent();
  TextView l=(TextView)p.findViewById(R.id.label);
  l.setText(model.toString());
 }
};

Everything works except the LinearLayout / getParent() downcast. At runtime it creates a ClassCastException. If I comment out that block of code then everthing works fine. What am I missing?

© Stack Overflow or respective owner

Related posts about android