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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:38:34+00:00 2026-05-26T08:38:34+00:00

My problem is when I change the text of a TextView in my Main

  • 0

My problem is when I change the text of a TextView in my Main class, it returns nullPointerException.

here’s my code:

main.xml

<TabHost ...>
  <RelativeLayout ...>
    <LinearLayout ...>
      <TabWidget .../>
       <FrameLayout ...>
        <ListView ../>
       </FrameLayout>
    </LinearLayout>

    <LinearLayout ...>
      <TextView android:id="@+id/status" ... />

    </LinearLayout>

  </RelativeLayout>
</TabHost>

Main class

....
TabHost tabHost;
TabHost.TabSpec spec;
Intent intent;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

    //display implementation of TabHost
    ....
    //Contacts tab
    intent = new Intent().setClass(this, Contacts.class);
    spec = tabHost.newTabSpec("contacts").setIndicator("Contacts",   res.getDrawable(R.drawable.ic_tab_contacts)).setContent(intent);
    tabHost.addTab(spec);

}

Then class that will update the status TextView is this:

Contacts class

public class Contacts extends ListActivity{
    public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);

       //gather info to display in ListView
       ....

       updateStatus("New Status");
    }

    private void updateStatus(String status){
       TextView labelView = (TextView) findViewById(R.id.status);
       labelView.setText(status);
    }

}


labelView.setText(status); Error occurs here....

Pls help me. I cant find any solution in the net.
I need to update the status….

heres my manifest:

...
 <application ...>
   <activity android:name=".Main" ... >
     <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
   </activity>

   <activity android:name=".Contacts"  android:label="@string/app_name"></activity> 
    <activity android:name=".OtherClass"  android:label="@string/app_name"></activity> 
    <activity android:name=".OtherClass2"  android:label="@string/app_name"></activity>
 </application>
...

In advance, thanks for any help.

  • 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-05-26T08:38:35+00:00Added an answer on May 26, 2026 at 8:38 am

    You see the view with id status exists in the Main activity context, while you are trying to find it from the Contacts activity context. Thats why it is returning null.

    Try this, it should solve your problem :

    Main Activity

    public class Main extends Activity {
    
        public static String sStatus = "";
    
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
                //display implementation of TabHost
                ....
    
        }
    
        @Override
        protected void onResume() {
            TextView labelView = (TextView) findViewById(R.id.status);
            labelView.setText(status);
        }
    }
    

    Contacts Activity

    public class Contacts extends ListActivity{
        public void onCreate(Bundle savedInstanceState){
           super.onCreate(savedInstanceState);
    
           //gather info to display in ListView
           ....
    
           updateStatus("New Status");
        }
    
        private void updateStatus(String status){
            Main.sStatus = status;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem I want to change my textview value. when my code
I use AsyncTask to change text of TextView like this: private class LongOperation extends
I'm having a problem getting a change event to register with the following code:
Hey here is my problem : i made a flash and i can`t change
I have a problem, I need to change body of method when this class
Code: public class SMH extends Activity { public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.main);
I've got an odd problem here. Basically I have a TextView with no default
I am facing background color change problem while using jquery. When the page loads
I implemented the table sorter yesterday and i have a problem trying to change
I have problem with c# script who change user AD password, when try change

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.