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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:35:49+00:00 2026-06-07T08:35:49+00:00

I’m getting a null pointer exception during runtime. I’m pulling in RelativeLayouts from 2

  • 0

I’m getting a null pointer exception during runtime. I’m pulling in RelativeLayouts from 2 XML files for the PagerView, which I seem to have messed up. Any idea what’s causing the error?

Thanks for any help!

I have two of these XML files that have this same structure–
player_turn_solution_component.xml:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/player_turn_solution_component"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/solutionCaption"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="what do you see?" />

        <EditText
            android:id="@+id/solutionInput"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/solutionCaption"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:ems="10" >

            <requestFocus />
        </EditText>

    </RelativeLayout>

My instanciation function:

@Override
    public Object instantiateItem(View collection, int position) {
        //Our specific component (TextView or ImageView, depending on posision
        //is placed inside a RelativeLayout that acts as a container
        RelativeLayout container = new RelativeLayout(pagerContext);
        TextView caption = new TextView(pagerContext);
        caption.setText("View: " + position);
        caption.setTypeface(typeface);
        caption.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        container.addView(caption);

        RelativeLayout optionLayout = null;
        TextView optionCaption = null;

        if (position == 0) {
            optionLayout = (RelativeLayout) findViewById(R.id.player_turn_solution_component);
            optionCaption = (TextView) findViewById(R.id.solutionCaption);
        } else if (position == 1) {
            optionLayout = (RelativeLayout) findViewById(R.id.player_turn_clue_component);
            optionCaption = (TextView) findViewById(R.id.clueCaption);
        }

        container.addView(optionLayout);

        ((ViewPager) collection).addView(container,0);  //get the container ready
        return container;   
    }

And the LogCat output:

07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewGroup.addView(ViewGroup.java:3158)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewGroup.addView(ViewGroup.java:3145)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at my.app.PlayerTurnActivity$HelpPagerAdapter.instantiateItem(PlayerTurnActivity.java:136)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:649)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.support.v4.view.ViewPager.populate(ViewPager.java:783)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1016)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.View.measure(View.java:12892)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.View.measure(View.java:12892)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.View.measure(View.java:12892)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1375)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.View.measure(View.java:12892)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2257)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.View.measure(View.java:12892)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1240)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.os.Looper.loop(Looper.java:137)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at android.app.ActivityThread.main(ActivityThread.java:4512)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at java.lang.reflect.Method.invokeNative(Native Method)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at java.lang.reflect.Method.invoke(Method.java:511)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
07-06 09:30:22.337: E/AndroidRuntime(8418):     at dalvik.system.NativeStart.main(Native Method)

EDIT: My new Activity contains the following, but crashes with the same NPE, but only when I swipe to change the pager view.

if (position == 0) {
        View v = getLayoutInflater().inflate(R.layout.player_turn_solution_component, null);                
        optionLayout = (RelativeLayout) v.findViewById(R.id.player_turn_solution_component);
    } else if (position == 1) {
        View v = getLayoutInflater().inflate(R.layout.player_turn_clue_component, null);    
        optionLayout = (RelativeLayout) v.findViewById(R.id.player_turn_clue_component);
    }

    container.addView(optionLayout);

    ((ViewPager) collection).addView(container,0);  //get the container ready
    return container;   
  • 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-07T08:35:51+00:00Added an answer on June 7, 2026 at 8:35 am

    You need something like this

    View v = getLayoutInflater().inflate(R.layout.layout_taht_have_player_turn_solution_component, null);
    

    and

     if (position == 0) {
                optionLayout = (RelativeLayout) v.findViewById(R.id.player_turn_solution_component);
                optionCaption = (TextView) v.findViewById(R.id.solutionCaption);
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.