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

  • Home
  • SEARCH
  • 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 8150021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:58:03+00:00 2026-06-06T14:58:03+00:00

I have the next sequence: create activity; place a fragment into it; go to

  • 0

I have the next sequence:

  • create activity;
  • place a fragment into it;
  • go to next fragment;
  • return to previous fragment with back button.

Okay, let’s do it.

This is how I go to next fragment in navigation:

public static void addFragment(Fragment currentFragment, Fragment fragment, int frameLayout) {
    FragmentTransaction fragmentTransaction = currentFragment.getFragmentManager().beginTransaction();
    fragmentTransaction.replace(frameLayout, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

public static void replaceFragment(Fragment currentFragment, Fragment fragment, int frameLayout) {
    FragmentManager fragmentManager = currentFragment.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment topFragment = fragmentManager.findFragmentById(frameLayout);
    int transactionsCount = fragmentManager.getBackStackEntryCount();
    if (transactionsCount > 0 && topFragment == currentFragment) {
        fragmentManager.popBackStack();
        fragmentTransaction.replace(frameLayout, fragment);
        fragmentTransaction.addToBackStack(null);
    }   else {
        fragmentTransaction.replace(frameLayout, fragment);
    }
    fragmentTransaction.commit();
}

In onCreateView of first fragment I load some data and hide activity indicator when it’s done

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout homeLayout = new LinearLayout(activity);
    inflater.inflate(R.layout.screen_home, homeLayout);

    setupCategoryButtons();
    setupHomeGenderRadioButton(mainLayout);
    setupMagazinesPreviews(mainLayout);

    return homeLayout;
}

private void setupCategoryButtons() {
    if(categoriesButtons.size() > 0) {
        View categoriesWaitIndicator = activity.findViewById(R.id.categoriesWaitIndicator);
        categoriesWaitIndicator.setVisibility(View.INVISIBLE);

        LinearLayout categoriesButtonsLayout = (LinearLayout)activity.findViewById(R.id.categoryButtonsLayout);

        for(CategoryButton categoryButton : categoriesButtons) {
            categoriesButtonsLayout.addView(categoryButton);
        }

        refreshCategoriesButtons();
    }
}

Nothing special. And it works perfectly. Until I return to this screen.

When I return to this screen I getting NullPointerException on those lines:

categoriesWaitIndicator.setVisibility(View.INVISIBLE);
categoriesButtonsLayout.addView(categoryButton);

It seems that the app cannot find those views! I tried to do it in onResume but it has the same effect. What am I doing wrong?

  • 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-06T14:58:05+00:00Added an answer on June 6, 2026 at 2:58 pm

    I don’t know exactly what this fragment does, but it’s manipulating views in the Activity. Since it’s possible for the fragment to exist before the Activity view is built or destroyed, it could be trying to get views that have been destroyed and/or modified by elements beyond its control. It would be much better if the fragment was isolated so it handled it’s own view.

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

Sidebar

Related Questions

I have a postgres table like this: CREATE SEQUENCE seq; CREATE TABLE tbl (id
I stuck into creating an XSD schema allowing only next sequence of elements: <root>
I have the following sequence: [as seen now in Toad]: CREATE SEQUENCE LOG_ID_SEQ START
I have created a sequence called as hibernate_sequnce using following command create sequence hibernate_sequence
I have a problem with some strings created by a sequence alignment program (this
I have next tables Order , Transaction , Payment . Class Order has some
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I have next problem: i have a View: <UserControl x:Class=WpfApplication1.UserControl1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have next html: <label for="user_name"> <abbr title="required">*</abbr> Name </label> And I want to

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.