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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:13:09+00:00 2026-06-10T05:13:09+00:00

Object: (Running API 8) Programmatically, I am trying to inflate the following onto a

  • 0

Object:
(Running API 8)
Programmatically, I am trying to inflate the following onto a single layout, main.xml

  • bg_content1.xml
  • bg_content2.xml
  • @+id/img_logo
  • @+id/str_username

Note:

  1. @+id/img_logo is an id of an ImageView located in bg_content3.xml
  2. @+id/str_username is an id of a TextView located in bg_content4.xml
  3. Please don’t ask me why I have to inflate multiple layouts and objects onto the other layout. I am trying to optimize my layouts for maintainability purposes.

main.xml

<LinearLayout android:id="@+id/main">
</LinearLayout>

bg_content1.xml

<LinearLayout android:id="@+id/bg_content1">
    <TextView
        android:text:"bg_content1 here"
        //other attributes omitted
    </TextView>
</LinearLayout>

bg_content2.xml

<LinearLayout android:id="@+id/bg_content2">
    <TextView
        android:text:"bg_content2 here"
        //other attributes omitted
    </TextView>
</LinearLayout>

bg_content3.xml

<LinearLayout android:id="@+id/bg_content2">
    <ImageView
        android:id:"@+id/img_logo"
        //other attributes omitted
    </TextView>
</LinearLayout>

bg_content4.xml

<LinearLayout android:id="@+id/bg_content4">
    <TextView
        android:id:"@+id/str_username"
        //other attributes omitted
    </TextView>
</LinearLayout>

MainActivity.xml

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LinearLayout container = (LinearLayout) findViewById(R.id.main);
    LayoutInflater inflater = LayoutInflater.from(this);
    LinearLayout bg_content = (LinearLayout) inflater.inflate(
        R.layout.bg_content1, null);
    container.addView(bg_content);

    bg_content = (LinearLayout) inflater.inflate(
        R.layout.bg_content2, null);
    container.addView(bg_content);

    ImageView bg_img = (ImageView) inflater.inflate(R.id.img_logo, null);
    container.addView(bg_img);

    TextView bg_str = (TextView) inflater.inflate(R.id.str_username, null);
    container.addView(bg_str);

}

logcat

08-26 14:16:43.457: D/AndroidRuntime(1726): Shutting down VM
08-26 14:16:43.457: W/dalvikvm(1726): threadid=1: thread exiting with uncaught exception (group=0x40015578)
08-26 14:16:43.558: E/AndroidRuntime(1726): FATAL EXCEPTION: main
08-26 14:16:43.558: E/AndroidRuntime(1726): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.ExLayoutInflaterActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.os.Looper.loop(Looper.java:130)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at java.lang.reflect.Method.invoke(Method.java:507)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at dalvik.system.NativeStart.main(Native Method)
08-26 14:16:43.558: E/AndroidRuntime(1726): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.content.res.Resources.getLayout(Resources.java:731)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at com.example.android.ExLayoutInflaterActivity.onCreate(ExLayoutInflaterActivity.java:26)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-26 14:16:43.558: E/AndroidRuntime(1726):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-26 14:16:43.558: E/AndroidRuntime(1726):     ... 11 more

SOLUTION PROVIDED BY @Ikaros
I have modified some minor syntactical errors below:

bg_content = (LinearLayout) inflater.inflate(
            R.layout.bg_content3, null);
container.addView(bg_content);

ImageView bg_img = (ImageView) bg_content.findViewById(R.id.img_logo);

bg_content = (LinearLayout) inflater.inflate(R.layout.bg_content4, null);
    container.addView(bg_content);

TextView bg_str = (TextView) bg_content.findViewById(R.id.str_username);
  • 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-10T05:13:11+00:00Added an answer on June 10, 2026 at 5:13 am

    For example in:

    ImageView bg_img = (ImageView) inflater.inflate(R.id.img_logo, null);
    container.addView(bg_img);
    

    you’re trying to inflate a child of your layout and I think this is your mistake.
    You can try something like:

    LinearLayout linear_layout = (LinearLayout) inflater.inflate(R.layout.bg_content3.xml, null);
    container.addView(linear_layout);
    

    If you need a reference to the ImageView you can refer to it as:

    (ImageView) bg_img = (ImageView) linear_layout.findViewById(R.id.bg_img);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running into a dilemma. When I make the ScrollViewer the main content object
When I tried running the following code product([1,2,3],['a','b']) it returned an object of the
Running the example code for the Facebook API I get a null session object,
I'm trying to use MapPoint's COM API from VB6, running it in application mode,
Running FB.api('/me/inbox', {limit:800}, function(response){ console.log(response)}); logs data: Array[50] summary: Object to the console, clearly
I'm running into a strange problem with testing an object's visibility with jQuery. I
I'm writing an Object Oriented OpenGL framework in perl and I'm running into a
I get this error: TypeError: object.__init__() takes no parameters when running my code, I
I'm building a javascript application using object oriented techniques and I'm running into a
What is the best way to shut down an object which is itself running

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.