NullPointerException with simple RatingBar
<p>I am learning Android by experimenting the <a href="http://developer.android.com/resources/tutorials/views/hello-formstuff.html" rel="nofollow">tutorial</a>. I got a weird NullPointerException when using a simple RatingBar. Here is my code:</p>

<pre><code>    public class HelloRatingBarActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
        ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Toast.makeText(HelloRatingBarActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
</code></pre>

<p>Here is the main.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" &gt;

     &lt;RatingBar android:id="@+id/ratingbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1.0"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Here is the log:</p>

<pre><code>12-13 21:51:51.878: D/gralloc_goldfish(530): Emulator without GPU emulation detected.
12-13 21:51:57.338: D/AndroidRuntime(530): Shutting down VM
12-13 21:51:57.338: W/dalvikvm(530): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
12-13 21:51:57.408: E/AndroidRuntime(530): FATAL EXCEPTION: main
12-13 21:51:57.408: E/AndroidRuntime(530): java.lang.NullPointerException
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:338)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.View.dispatchTouchEvent(View.java:5462)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1680)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1680)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1680)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1680)
12-13 21:51:57.408: E/AndroidRuntime(530):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1882)
12-13 21:51:57.408: E/AndroidRuntime(530):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1361)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
12-13 21:51:57.408: E/AndroidRuntime(530):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1830)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.View.dispatchPointerEvent(View.java:5638)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2827)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2406)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.os.Looper.loop(Looper.java:137)
12-13 21:51:57.408: E/AndroidRuntime(530):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-13 21:51:57.408: E/AndroidRuntime(530):  at java.lang.reflect.Method.invokeNative(Native Method)
12-13 21:51:57.408: E/AndroidRuntime(530):  at java.lang.reflect.Method.invoke(Method.java:511)
12-13 21:51:57.408: E/AndroidRuntime(530):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-13 21:51:57.408: E/AndroidRuntime(530):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-13 21:51:57.408: E/AndroidRuntime(530):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>I have no idea how the NullPointerException happened. Any help is appreciated!</p>
