Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:38:55+00:00 2026-06-02T10:38:55+00:00

Java code of the button image changing,Java code of the button image changing public

  • 0

Java code of the button image changing,Java code of the button image changing

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();


    }

Layout of the button exist,Layout of the button exist

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.10" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >

            <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" />

            <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" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >

            <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" />

            <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" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >

            <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" />

            <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" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >
        </TableRow>
    </TableLayout>F

</LinearLayout>

Please help this not working? I want to change the button background image in code??I get null point exception…

Log of the error,Log of the error,Log of the error

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:39:02+00:00Added an answer on June 2, 2026 at 10:39 am
    Button btn=(Button)findViewById(R.id.level1);
    btn.setBackgroundColor(Color.BLUE);
    

    paste the above two lines below

    setContentView(R.layout.levels);
    

    we need to first set content view then do the initialization task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.
My Java code must get string HH:MM from console and needs to operate with
I have some Java code which performs bitwise operations on a BitSet. I have
I have this Java code, and I want to do the same thing in
I run a Java code with the following command: $ java -Xms4G -Xmx4G myjavacode
In the Java code for our application I'm pretty sure there are lots of
In my Java code, I occasionally run into situations where I have to catch
I have some Java code that is throwing out of memory exceptions after running
In my Java code I have function that gets file from the client in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.