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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:00:18+00:00 2026-05-20T05:00:18+00:00

Evening :) I have a little problem… As you can see in my code

  • 0

Evening 🙂

I have a little problem…

As you can see in my code below, the Textview which i am trying to setText on, is getting me a Nullpointer 🙁

Is there anyone which can tell me what i am doing wrong ? 🙂

And the string s isnt null or, it is the view itself. It is working when setting the text in the oncreate().

Thanks..

public class smsShower extends Activity{

    private TextView status;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.show);
        //status = (TextView)findViewById(R.id.status);

        status = (TextView)findViewById(R.id.status);
    }

    public void displayText(String s){

        status.setText(s);

    }

}

smsReceiverclass:

public class smsreceiver extends BroadcastReceiver {


    private String str;

    private boolean received = false;

    private smsShower smsshow;

    @Override
    public void onReceive(Context context, Intent intent) {
           //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();       
        smsshow = new smsShower();

        SmsMessage[] msgs = null;
        str = "";            
        if (bundle != null)
        {

            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];  


            for (int i=0; i<msgs.length; i++){

                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); 

                if(msgs[i].getDisplayOriginatingAddress().equals("1990"))
                {
                    received = true;
                    str += msgs[i].getMessageBody().toString();

                    smsshow.displayText(str);



                }

Layout:

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

<TextView android:id="@+id/status" android:layout_alignParentTop="true" android:text="Status:" android:layout_height="match_parent" android:layout_width="match_parent"></TextView>
</RelativeLayout>

Error Log:

02-18 01:14:20.064: ERROR/AndroidRuntime(18964): Caused by: java.lang.NullPointerException
02-18 01:14:20.064: ERROR/AndroidRuntime(18964):     at com.sms1990.smsShower.displayText(smsShower.java:36)
02-18 01:14:20.064: ERROR/AndroidRuntime(18964):     at com.sms1990.smsreceiver.onReceive(smsreceiver.java:47)
02-18 01:14:20.064: ERROR/AndroidRuntime(18964):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2941)
  • 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-20T05:00:19+00:00Added an answer on May 20, 2026 at 5:00 am

    Add a basic null check as follows:

    public void displayText(String s){
      if (status != null)
        status.setText(s);
    
    }
    

    you’ll not get NPE. How do you start activity and get a reference to it in broadcast reciever?

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

Sidebar

Related Questions

Good evening I've got a little problem with my DataGridView in a .NET Windows
Good evening, people! I'm trying to solve a rather simple problem, but.. well, it
Evening all. I have the following code that I need looking into - basically
Good evening stackoverflow. I have a problem involving JOptionPanes. Every so often they simply
I posted this question yesterday evening, which has led me to discover a huge
Good evening I have a JTable that I built with a TableModel how to
We have a very large number of SSIS jobs that are scheduled every evening/early
Good Evening All, I have a textbox that needs to accept 14 digits plus
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in

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.