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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:08:17+00:00 2026-06-18T10:08:17+00:00

I want to add an Image in an existing Layout. I create the Image

  • 0

I want to add an Image in an existing Layout. I create the Image with this code snippet:
http://www.inter-fuser.com/2009/12/android-reflections-with-bitmaps.html

This class creates a ImageView with the right image. I want to add the Image in this 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="wrap_content"
    android:orientation="horizontal" >

    <include
        android:id="@+id/actionbar_back"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/actionbar_back" />

    <LinearLayout
        android:id="@+id/ll_ueberschrift"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/gray" 
        android:gravity="center"
        android:layout_below="@id/actionbar_back" >

        <TextView
            android:id="@+id/tv_ueberschrift"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Java" 
            android:layout_gravity="right" 
            android:textSize="30sp" />       
    </LinearLayout>


        <!--  ListRow Left sied Thumbnail image -->

    <LinearLayout
        android:id="@+id/ll_thumbnail" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"      
        android:layout_alignParentLeft="true"
        android:layout_marginRight="5dip"
        android:layout_marginTop="20dp"
        android:layout_below="@id/ll_ueberschrift" >

        <ImageView
            android:id="@+id/iv_objekt"
            android:contentDescription="@string/description"
            android:layout_width="120sp"
            android:layout_height="120sp"
            android:paddingLeft="5dp" />
    </LinearLayout>
<RelativeLayout>

Now I try to add the Image to the existing ImageView:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   ...

   //Create an Image view and add our bitmap with reflection to it
   ImageView imageView = new ImageView(this);
   imageView.setImageBitmap(bitmapWithReflection);
   imageView.setPadding(5, 5, 5, 5);

    View linearLayout =  findViewById(R.id.ll_picture_and_reflection);
    ((LinearLayout) linearLayout).addView(imageView);
    setContentView(R.layout.objekt_einzeln); 
}

But I just a get “NullPointerException”.

Any suggestion what to do or what is incorrect?
Thank a lot

EDIT: I meant “View linearLayout = findViewById(R.id.iv_objekt);”

  • 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-18T10:08:18+00:00Added an answer on June 18, 2026 at 10:08 am

    You are doing setContentView after you are trying to reference the LinearLayout. Do this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.objekt_einzeln); 
    
       //Create an Image view and add our bitmap with reflection to it
       ImageView imageView = new ImageView(this);
       imageView.setImageBitmap(bitmapWithReflection);
       imageView.setPadding(5, 5, 5, 5);
    
        View linearLayout =  findViewById(R.id.ll_picture_and_reflection);
        ((LinearLayout) linearLayout).addView(imageView);
    
    }
    

    But even then you are referencing a LinearLayout which is not in that XML you provided.

    Make sure you do setContentView first, then make sure the LinearLayout is actually in the layout you provide in setContentView

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

Sidebar

Related Questions

I want to add multiple borders on a single image. Is this possible through
Hi I want to add image in table cell according to condition in table.
I want to add an image, instead of the default button. I already have
I want to add background image to uinavigationcontroller. Please help me.
I want to add an image to be a background of the header, the
I want to add a background image to a bar chart using Highcharts and
I am very new to Java, I want to add a PNG image to
Hi an developing drawing android application. in that i want to add a sticker(image)
i want to add images or labels with image in it to a panel
I want to add a link to every image in the HTML with the

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.