Class cast exception on rating bar?
<p>I am getting a class cast exception on <code>RatingBar</code> when I try to execute my applications. Here is the <code>logcat</code>:</p>

<pre><code>06-15 11:27:55.585: ERROR/AndroidRuntime(385): FATAL EXCEPTION: main
06-15 11:27:55.585: ERROR/AndroidRuntime(385): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apps.niit.rating/com.apps.niit.rating.MovieRatingActivity}: java.lang.ClassCastException: android.widget.RatingBar
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.os.Looper.loop(Looper.java:123)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at java.lang.reflect.Method.invokeNative(Native Method)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at java.lang.reflect.Method.invoke(Method.java:521)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at dalvik.system.NativeStart.main(Native Method)
06-15 11:27:55.585: ERROR/AndroidRuntime(385): Caused by: java.lang.ClassCastException: android.widget.RatingBar
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at com.apps.niit.rating.MovieRatingActivity.onCreate(MovieRatingActivity.java:27)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-15 11:27:55.585: ERROR/AndroidRuntime(385):     ... 11 more
</code></pre>

<p>The code of my main activity is as follows:</p>

<pre><code>import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.Toast;

public class MovieRatingActivity extends Activity {
    /** Called when the activity is first created. */
    private EditText movieName;
    private EditText userReview;
    private EditText releaseYear;
    private EditText movieDuration;
    RatingBar yourRating;
    private EditText movieStarring;
    private EditText movieDirector;
    private ImageView movieImage;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        movieName = (EditText)findViewById(R.id.editText2);
        userReview = (EditText)findViewById(R.id.editText1);
        releaseYear = (EditText)findViewById(R.id.editText3);
        movieDuration = (EditText)findViewById(R.id.editText4);
        yourRating = (RatingBar)findViewById(R.id.ratingBar1);
        movieStarring = (EditText)findViewById(R.id.editText5);
        movieDirector = (EditText)findViewById(R.id.editText6);
        movieImage = (ImageView)findViewById(R.id.imageView1);
        yourRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){

               @Override
               public void onRatingChanged(RatingBar ratingBar, float rating,
                 boolean fromUser) {
                // TODO Auto-generated method stub
                   yourRating.setRating(rating);
                   Toast.makeText(MovieRatingActivity.this, "rating:"+String.valueOf(rating),
                  Toast.LENGTH_LONG).show();
               }});
        movieImage.setImageResource(R.drawable.icon);       
    }
    public void myCickHandler(View view){
        Intent myIntent = new Intent(MovieRatingActivity.this, null);
        Bundle myBundle = new Bundle();     
        myBundle.putString("key1", movieName.getText().toString());
        myBundle.putString("key1", userReview.getText().toString());
        myBundle.putString("key1", releaseYear.getText().toString());
        myBundle.putString("key1", movieDuration.getText().toString());
        myBundle.putDouble("key1", yourRating.getRating());
        myBundle.putString("key1", movieStarring.getText().toString());
        myBundle.putString("key1", movieDirector.getText().toString()); 
        myIntent.putExtras(myBundle);
        startActivity(myIntent);
    }
}
</code></pre>

<p>The layout file markup is as follows:</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical" android:gravity="top"&gt;
    &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:hint="Movie name" android:id="@+id/editText2" android:text=""&gt;&lt;/EditText&gt;
    &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal"&gt;
        &lt;LinearLayout android:id="@+id/linearLayout2" android:layout_height="match_parent" android:layout_width="wrap_content"&gt;
            &lt;ImageView android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="match_parent"&gt;&lt;/ImageView&gt;
        &lt;/LinearLayout&gt;
        &lt;LinearLayout android:id="@+id/linearLayout3" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"&gt;
            &lt;LinearLayout android:id="@+id/linearLayout4" android:layout_height="match_parent" android:orientation="vertical" android:layout_width="match_parent"&gt;
                &lt;LinearLayout android:id="@+id/linearLayout6" android:layout_height="wrap_content" android:layout_width="match_parent"&gt;
                    &lt;EditText android:text="" android:hint="Year" android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number"&gt;&lt;/EditText&gt;
                    &lt;EditText android:layout_height="wrap_content" android:hint="Duration" android:layout_weight="1" android:layout_width="wrap_content" android:id="@+id/editText4" android:text=""&gt;&lt;/EditText&gt;
                &lt;/LinearLayout&gt;
            &lt;/LinearLayout&gt;
            &lt;LinearLayout android:id="@+id/linearLayout5" android:layout_height="match_parent" android:layout_width="wrap_content" android:orientation="vertical"&gt;
                &lt;RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/RatingBar&gt;
            &lt;/LinearLayout&gt;
        &lt;/LinearLayout&gt;
    &lt;/LinearLayout&gt;
    &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/editText1" android:text="" android:hint="Write review here" android:layout_weight="1" android:gravity="top"&gt;&lt;/EditText&gt;
    &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/editText5" android:text="" android:hint="Starring"&gt;&lt;/EditText&gt;
    &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/editText6" android:text="" android:hint="Director"&gt;&lt;/EditText&gt;
    &lt;Button android:layout_height="wrap_content" android:text="Save" android:id="@+id/button1" android:layout_width="match_parent"&gt;&lt;/Button&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>I am not been able to figure out the issue as casting is proper.</p>
