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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:13:20+00:00 2026-06-08T12:13:20+00:00

I created a linearlayout which includes the same linear layout four times, to get

  • 0

I created a linearlayout which includes the same linear layout four times, to get a sort of list. But when i try to change the background color of one of these included layouts, i get an nullpointerexception. Anyone got an idea why and how to solve it?

my class:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.overview);

        String language =  Locale.getDefault().getISO3Language();
        georgiaI = Typeface.createFromAsset(getAssets(), "georgiai.ttf");  
        arialB = Typeface.createFromAsset(getAssets(), "arialbd.ttf");  


        llPlaces= (LinearLayout)findViewById(R.id.ll_overview_list_places);


        // Places
        llitem1= (LinearLayout)llPlaces.findViewById(R.id.lloverview);
        llitem1.setBackgroundColor(R.color.list_even);
        String item1a;
        String item1b;
        if(language.equals("nld")){
            item1a = "dutchstring";
            item1b = "dutchstring";
        }else{
            item1a = "englishString";
            item1b = "englishString";
        }
        tvitem1a=(TextView)llPlaces.findViewById(R.id.tvoverviewname);
        tvitem1a.setTypeface(arialB);
        tvitem1a.setText(item1a.toUpperCase());
        tvitem1b=(TextView)llPlaces.findViewById(R.id.tvoverviewtext);
        tvitem1b.setTypeface(georgiaI);
        tvitem1b.setText(item1b);
        iv1= (ImageView)llPlaces.findViewById(R.id.ivoverviewimage);
        iv1.setImageResource(R.drawable.categories_places);

the line where the NPE occurs is: llitem1.setBackgroundColor(R.color.list_even);
I want alternating colors, thats why i didn’t add the color in the xml. Offcourse i can make two xml files, for different colors, but this should work.

xml files:

overview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@color/orange">

     <include
            android:id="@+id/bt_overview_list_places"
            layout="@layout/single_overview_item" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
      <include
            android:id="@+id/bt_overview_list_agenda"
            layout="@layout/single_overview_item" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
       <include
            android:id="@+id/bt_overview_list_shopping"
            layout="@layout/single_overview_item" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
        <include
            android:id="@+id/bt_overview_list_food"
            layout="@layout/single_overview_item" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>


</LinearLayout>

single overview item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/lloverview"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@color/custom_button_grey"
  >
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
  >
  <ImageView
      android:id="@+id/ivoverviewimage"
      android:layout_width="50dp"
      android:layout_height="50dp" android:src="@drawable/ic_launcher" android:scaleType="centerCrop"
      android:layout_margin="10dp"
      android:layout_weight="1"/>

  <LinearLayout
      android:layout_width="225dp"
      android:layout_height="wrap_content"
      android:orientation="vertical" >

  <TextView
      android:id="@+id/tvoverviewname"
      android:layout_width="225dp"
      android:layout_height="wrap_content"
      android:layout_gravity="left|top"
      android:layout_marginLeft="10dip"
      android:text="naam"
      android:textSize="16dip" 
      android:maxLines="1"
      android:ellipsize="marquee"
      android:textColor="@color/black"/>

 <TextView
     android:id="@+id/tvoverviewtext"
     android:layout_width="225dp"
     android:layout_height="wrap_content"
     android:layout_marginLeft="10dip"
     android:maxLines="3"
     android:text="tip"
     android:textSize="12dip" 
     android:ellipsize="end"
     android:textColor="@color/black"/>

 </LinearLayout>



 <ImageView 
     android:id="@+id/arrow"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:src="@drawable/iconarrowsmall"
      android:layout_gravity="center_vertical"
      android:layout_margin="2dip"
     />

</LinearLayout>
<ImageView 
     android:id="@+id/bottom_border"
     android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:src="@drawable/custombuttonlist_bottomborder"
     />

</LinearLayout>
  • 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-08T12:13:21+00:00Added an answer on June 8, 2026 at 12:13 pm

    If your setting different ids for the include elements then your code should be like this(there isn’t anymore a LinearLayout with the id lloverview in the layout):

    llPlaces= (LinearLayout)findViewById(R.id.ll_overview_list_places);
    llPlaces.setBackgroundColor(R.color.list_even);
    

    If you set an id to the include tag then this will be the id for the root view of the added layout.

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

Sidebar

Related Questions

I'm a newbie developer, I created a layout which matches my expectations but I
I created 5 buttons dynamically in a LinearLayout vertically. They get their names from
I created one linear layout and I have added two relative layout. I wish
I created one Linear layout inside scroll view (Horizontal) in xml with number of
I have created a specific List which exists out of the following elements to
I have created a custom tab layout which look like this,I want to make
I created a file in \res\layout named contactlist.xml But it is not recognized in
I have a layout, which include some TextViews and ImageViews. Haven't they created an
I want to count how many times a button (which are created dynamically) is
I have a linear layout which holds inner (child) custom image view. My goal

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.