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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:48:19+00:00 2026-05-23T02:48:19+00:00

Iam getting a null pointer exception while sending some string text as an sms

  • 0

Iam getting a null pointer exception while sending some string text as an sms to other emulator.I have a button which on clicking will send the text present in the textView as an sms to other emulator.

Here is the code of textview and button class

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




         SecureMessagesActivity sma = new SecureMessagesActivity();

         message = sma.getMessageBody();
         tv= (TextView) findViewById(R.id.textView1);
           tv.setText(message); 



         submit = (Button) findViewById(R.id.button1);
         submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

    SendSms sms = new SendSms();
    sms.sendSMS("15555215556", message);

}});

  }

and here is the code of sendsms class

public class SendSms extends Activity {

    public void sendSMS(String phoneNumber, String message)
    {        
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @SuppressWarnings("deprecation")
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        }, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
    }

}

now on clicking the button the device gets force close message, the error in logcat is

06-14 17:47:47.249: ERROR/AndroidRuntime(8403): FATAL EXCEPTION: main
06-14 17:47:47.249: ERROR/AndroidRuntime(8403): java.lang.NullPointerException
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.app.PendingIntent.getBroadcast(PendingIntent.java:226)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at com.mypackage.ULWAFMS1.SendSms.sendSMS(SendSms.java:38)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at com.mypackage.ULWAFMS1.page1$1.onClick(page1.java:43)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.view.View.performClick(View.java:2408)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.view.View$PerformClick.run(View.java:8816)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.os.Handler.handleCallback(Handler.java:587)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.os.Looper.loop(Looper.java:123)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at java.lang.reflect.Method.invokeNative(Native Method)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at java.lang.reflect.Method.invoke(Method.java:521)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-14 17:47:47.249: ERROR/AndroidRuntime(8403):     at dalvik.system.NativeStart.main(Native Method)
  • 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-23T02:48:20+00:00Added an answer on May 23, 2026 at 2:48 am

    The problem is occurring where you are creating your PendingIntent objects at the start of your sendSms method. You are implementing SendSMS as an activity, but I don’t think that it needs to be, and it is not being correctly initialised as an Activity, so you are seeing this failure.

    Take out the extends Activity from your sendsms class, and change your sendSms method to start as follows:

    public class SendSms {
    
        public void sendSMS(Context context, String phoneNumber, String message)
        {        
            String SENT = "SMS_SENT";
            String DELIVERED = "SMS_DELIVERED";
    
            PendingIntent sentPI = PendingIntent.getBroadcast(context, 0,
                new Intent(SENT), 0);
    
            PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,
                new Intent(DELIVERED), 0);
    

    Now you’ll need to call it as sendSms( this, "15555215556", message ); from your onClickListener;

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

Sidebar

Related Questions

Checkbox[,] checkArray = new Checkbox[2, 3]{{checkbox24,checkboxPref1,null}, {checkbox23,checkboxPref2,null}}; I am getting error . How do
I am getting some errors thrown in my code when I open a Windows
I am facing a problem while debugging in Eclipse 3.4.2. I keep getting pop-up
I am having some problems in getting a loop to work. My goal is
I am getting back into a bit more .NET after a few-years of not
I am getting C++ Compiler error C2371 when I include a header file that
I am getting the following error: Access denied for user 'apache'@'localhost' (using password: NO)
I am getting a NoClassDefFoundError when I run my Java application. What is typically
I am getting this error now that I hit version number 1.256.0: Error 4
I am getting this error when trying to run internet information services on a

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.