Button image change error in code
<p>Java code of the button image changing,Java code of the button image changing   </p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);



        Button btn=(Button)findViewById(R.id.level1);
            btn.setBackgroundColor(Color.BLUE);




        // setContentView(new Gameview(this)`enter code here`);
        setContentView(R.layout.levels);
        addListenerOnButton();


    }
</code></pre>

<p>Layout of the button exist,Layout of the button exist</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="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/levelbackground"
    android:gravity="center_vertical"
    android:orientation="horizontal" &gt;

    &lt;TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.10" &gt;

        &lt;TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" &gt;

            &lt;Button
                android:id="@+id/level1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/level1"
                android:height="79dp"
                android:width="80dp" /&gt;

            &lt;Button
                android:id="@+id/level2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/levelloked"
                android:height="79dp"
                android:width="80dp" /&gt;
        &lt;/TableRow&gt;

        &lt;TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" &gt;

            &lt;Button
                android:id="@+id/level3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/levelloked"
                android:height="79dp"
                android:width="80dp" /&gt;

            &lt;Button
                android:id="@+id/level4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/levelloked"
                android:height="79dp"
                android:width="80dp" /&gt;
        &lt;/TableRow&gt;

        &lt;TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" &gt;

            &lt;Button
                android:id="@+id/level5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/levelloked"
                android:height="79dp"
                android:width="80dp" /&gt;

            &lt;Button
                android:id="@+id/level6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/levelloked"
                android:height="79dp"
                android:width="80dp" /&gt;
        &lt;/TableRow&gt;

        &lt;TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" &gt;
        &lt;/TableRow&gt;
    &lt;/TableLayout&gt;F

&lt;/LinearLayout&gt;
</code></pre>

<p>Please help  this not working? I want to change the button background image in code??I get null point exception...</p>

<p>Log of the error,Log of the error,Log of the error</p>

<pre><code>04-19 08:28:43.279: I/ApplicationPackageManager(3716): cscCountry is not German : XSG
04-19 08:28:43.279: D/AndroidRuntime(3716): Shutting down VM
04-19 08:28:43.279: W/dalvikvm(3716): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-19 08:28:43.289: E/AndroidRuntime(3716): FATAL EXCEPTION: main
04-19 08:28:43.289: E/AndroidRuntime(3716): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hunter99x/com.hunter99x.LevelsScreen}: java.lang.NullPointerException
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.os.Looper.loop(Looper.java:123)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread.main(ActivityThread.java:3687)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at java.lang.reflect.Method.invoke(Method.java:507)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at dalvik.system.NativeStart.main(Native Method)
04-19 08:28:43.289: E/AndroidRuntime(3716): Caused by: java.lang.NullPointerException
04-19 08:28:43.289: E/AndroidRuntime(3716):     at com.hunter99x.LevelsScreen.onCreate(LevelsScreen.java:21)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-19 08:28:43.289: E/AndroidRuntime(3716):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-19 08:28:43.289: E/AndroidRuntime(3716):     ... 11 more
</code></pre>
