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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:28:46+00:00 2026-06-14T10:28:46+00:00

Within my main Activity, I create a FrameLayout with child Views and set it

  • 0

Within my main Activity, I create a FrameLayout with child Views and set it as the ContentView. Now, staying within the same Activity, after onCreate() has executed fully, I need to be able to add and remove child Views from the FrameLayout, dynamically. I achieved this by using a Handler to pause the main Thread and then add or removed the child Views as needed.

This all works great when I am dealing with Views that I programmatically create, but when I attempt to do the same with a View that uses a XML layout, I get a Null Pointer Exception from the ViewGroup that I am trying to add to the FrameLayout.

Are there specific steps I can use to achieve this without the use of Fragments?

I can elaborate more if some don’t understand what I am asking. I could provide code chunks if it would help but I think most will get the gist of what I am doing from my short explanation. I am just looking for someone to point me into the right direction.

Here is the LogCat chunk for the exception taht was thrown:

11-15 13:40:42.977: E/AndroidRuntime(14956): FATAL EXCEPTION: main
11-15 13:40:42.977: E/AndroidRuntime(14956): java.lang.NullPointerException
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.view.ViewGroup.addView(ViewGroup.java:1821)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.view.ViewGroup.addView(ViewGroup.java:1808)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.beastcodes.framework.impl.AndroidGame.addScreenFragment(AndroidGame.java:207)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.beastcodes.framework.impl.AndroidGame.addAllScreenFragments(AndroidGame.java:213)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.beastcodes.framework.impl.AndroidGame.access$2(AndroidGame.java:211)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.beastcodes.framework.impl.AndroidGame$3.run(AndroidGame.java:61)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.os.Handler.handleCallback(Handler.java:587)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.os.Looper.loop(Looper.java:130)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at android.app.ActivityThread.main(ActivityThread.java:3691)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at java.lang.reflect.Method.invokeNative(Native Method)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at java.lang.reflect.Method.invoke(Method.java:507)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
11-15 13:40:42.977: E/AndroidRuntime(14956):    at dalvik.system.NativeStart.main(Native Method)
  • 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-14T10:28:47+00:00Added an answer on June 14, 2026 at 10:28 am

    You have to inflate views from XML using a LayoutInflater before adding them to the FrameLayout.

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

Sidebar

Related Questions

Often I create Child threads within the main() as Thread thread = new Thread(new
I'm trying to create an Android test project from within my main project. Exactly
I have 2 classes within same package. Both classes have main method in them.
//main activity in this class two errors shown below within the comments import android.graphics.Color;
I'm trying to display my main activity from within another class, but the problem
I have an Android app with a main tab activity, and several activities within
I'm trying to dispose and restart an OpenGLView or AndroidGameView within the same Activity,
I have 2 internal div's within a main div JSfiddle - http://jsfiddle.net/uwdnH/ Illustration -
I have 2 files, main.html and search.php . Within the main.html page, there is
I am designing a potal framework and I have multiple portlets(divs) within the main

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.