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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:01:06+00:00 2026-06-07T15:01:06+00:00

I am trying to create a notepad app that has three tabs at the

  • 0

I am trying to create a notepad app that has three tabs at the top, each linking to a different view.

The first two tabs will simply contain a form to fill out while the third will be where the actual writing is done. The problem is whenever I try to try to inflate this third view I am getting a null pointer exception for this line:

((LinearLayout) findViewById(R.id.drawRoot)).addView(v,0);

Here is my code:

public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    // When the given tab is selected, show the tab contents in the container
    Fragment fragment = new Section3Fragment();
    Bundle args = new Bundle();
    args.putInt(Section3Fragment.ARG_SECTION_NUMBER, tab.getPosition() + 1);
    fragment.setArguments(args);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.container3, fragment)
            .commit();
}


public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}


public  class Section3Fragment extends Fragment {
    public Section3Fragment() {
    }

    int section;
    public static final String ARG_SECTION_NUMBER = "section_number";

    @Override
    public  View  onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        Bundle args = getArguments();
       section = args.getInt(ARG_SECTION_NUMBER);
       View view;

       if (section == 1)
       {
            view = inflater.inflate(R.layout.section3_page1, container,false);

           return view;
       }
       if (section == 2){

        view = inflater.inflate(R.layout.section3_page2, container, false);
        return view;
       }
       else {


            if(v != null)
                Log.v("not null", "not null");

            view = inflater.inflate(R.layout.section3_page3, container, false);
            ((LinearLayout) findViewById(R.id.drawRoot)).addView(v,0); //null pointer exception here!!


           return view;

       }
    }
}

The object v is an instance on the class I use to do the actual drawing.

And the section3_page3 layout file

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

Any insight into this issue is greatly appreciated.

  • 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-07T15:01:08+00:00Added an answer on June 7, 2026 at 3:01 pm

    At a quick glance, are you trying to do:

     ((LinearLayout) view.findViewById(R.id.drawRoot)).addView(v,0);
    

    Your looking for the view on your fragment. not on the view you inflated within the if statement.

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

Sidebar

Related Questions

I'm trying to create a generic, reusable view, that looks like a lined notepad.
I'm trying to create a Temp Table that has a key field that auto
Trying to create a black line in my view to separate text blocks but
Trying to create a facebook app just to learn and coming across a strange
I am trying to create a simple notepad in Java. This is the code
I'm trying to create a notepad/wordpad clone. I want to save it in .rtf
I have an executable (say notepad.exe). I am trying to create a function map
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I am trying to create a permanent wmi event consumer that will wait for
I'm currently trying create a service that will return results of a OLAP cube

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.