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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:13:51+00:00 2026-06-14T08:13:51+00:00

First of I tried the tips in the example here (getActivity) but it doesn’t

  • 0

First of I tried the tips in the example here (getActivity) but it doesn’t work

TextView text = (TextView)
getActivity().findViewById(R.nrOfBooksInCollection);//This results in nullpointer exception
text.setText("Text from a fragment");//This results in nullpointer exception

And neiter does the below code work. I don’t get an error in Eclipse using the below code, it just doesn’t change the text in the textview “nrOfBooksInCollection”.

package com.ahmad.actionBar;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TextView;

public class FragMent2 extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.summary, null);
    SimpleBookManager testBook = new SimpleBookManager();
    TextView nrOfBooksfield = (TextView) view.findViewById(R.id.nrOfBooksInCollection);
        String text = Integer.toString(testBook.count());
        nrOfBooksfield.setText(text);//The text doesn't change at all
        nrOfBooksfield.setText("text");//Neither does this
        return inflater.inflate(R.layout.summary, container, false);
    }
    }

It worked when I was using Activities so the XML file is fine.

  • 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-14T08:13:52+00:00Added an answer on June 14, 2026 at 8:13 am

    You are inflating your view outside your ViewGroup. Try:

    View view = inflater.inflate(R.layout.summary, container, null);
    ...
    return view;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble getting minizip to work on android. I first tried to
At first,I tried to use ppm and cpanm to install Tk module.But failed to
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
this is my first question, although I've already used so many tips from Stack
Noob question here. I'm following this example/tutorial to try and isolate a problem I
I have tried some tips I was given on regards URL encoding but I
I am trying to communicate between an applet and a servlet. I first tried
I first time tried to subClassed an NSDate to give it 2 methods that
So I am trying to update NodeJS and running into issues. First I tried
I am trying to parse the resultlist of http://mobile.de . First I tried it

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.