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 6837839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:31:30+00:00 2026-05-26T23:31:30+00:00

I have <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:id=@+id/mainRelativeLayout> and I’m trying to setup the background

  • 0

I have

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/mainRelativeLayout">

and I’m trying to setup the background using java code (I don’t want to do it in xml) using this code in onCreate method:

View view = (View)findViewById(R.id.mainRelativeLayout);
        view.setBackgroundColor(0xFF000000);

or this code:

View view = (View)findViewById(R.id.mainRelativeLayout);
        view.setBackgroundColor(android.R.color.white);

However, it fails at first line when it tries to find the id. Where’s the problem? Thanks

start of my onCreate() code:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getPrefs();
        if (themePreference) {
            setTheme(android.R.style.Theme_Light_NoTitleBar);
        }else{
            setTheme(android.R.style.Theme_Black_NoTitleBar);
        }
        setContentView(R.layout.main);
        /*View view = (View)findViewById(R.id.mainRelativeLayout);
        view.setBackgroundColor(0xFF000000);*/

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

        this.submitBtn = (Button) this.findViewById(R.id.submitBtn);
        this.cleanBtn = (Button) this.findViewById(R.id.clear_txt_Input);
        this.inputQ = (EditText) this.findViewById(R.id.inputQ);
        ...

stack trace:

myApp [Android Application] 
    DalvikVM[localhost:8610]    
        Thread [<1> main] (Suspended (exception RuntimeException))  
            ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1768    
            ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1784 
            ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 123   
            ActivityThread$H.handleMessage(Message) line: 939   
            ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
            Looper.loop() line: 130 
            ActivityThread.main(String[]) line: 3835    
            Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
            Method.invoke(Object, Object...) line: 507  
            ZygoteInit$MethodAndArgsCaller.run() line: 847  
            ZygoteInit.main(String[]) line: 605 
            NativeStart.main(String[]) line: not available [native method]  
        Thread [<8> Binder Thread #2] (Running) 
        Thread [<7> Binder Thread #1] (Running) 
  • 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-05-26T23:31:30+00:00Added an answer on May 26, 2026 at 11:31 pm

    Were you able to run your app successfully without changing the background color? Because I was able to run a simplified version of your code without any errors. I think your error might be elsewhere.

    Have you tried using Project > Clean to clean and rebuild your project?

    Here is the test code I used.

    The Activity:

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        View view = findViewById(R.id.mainLayout);
        view.setBackgroundColor(0xFFEE3333);
    }
    

    And the XML:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/mainLayout">
    
        <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Stack Overflow"/>
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this layout: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content android:layout_gravity=center android:cacheColorHint=#0000 android:background=@layout/selectorgreybutton > <LinearLayout android:orientation=horizontal
I have a RelativeLayout like this: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginTop=10dip> <Button android:id=@+id/negativeButton
I have a layout like this: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical > <include layout=@layout/basicinfo
i have in xml tis code: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/mainLayout android:layout_width=wrap_content android:layout_height=wrap_content> <Button android:id=@+id/examp1 android:layout_width=wrap_content
I have created a custom listView with the row as follows: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
<?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/messageLayout android:layout_width=fill_parent android:layout_height=wrap_content> <ImageView android:id=@+id/messageSender android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginRight=10dp android:layout_marginLeft=10dp
Here is some xml for a row in a ListView: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content
<?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <org.zestadz.ads.ZestadzAd android:id=@+id/ad android:layout_width=fill_parent android:layout_height=wrap_content android:layout_alignParentBottom=true android:clickable=true
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have the following layout defined in XML: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_height=wrap_content

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.