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

The Archive Base Latest Questions

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

Hello I got the NullPointerException when I send the message I cant understand why

  • 0

Hello I got the NullPointerException when I send the message I cant understand why this happned. i posted my code below:-

BroadCastReceiver:-

package z.z.z;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class SMSReceiver extends BroadcastReceiver  
{
    private SmsMessage[] msgs;
    private String strNo,strMsgText;

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        try
        {
            Bundle bundle = intent.getExtras();        
            msgs = null;
            String 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]);
                    str += "SMS from " + msgs[i].getOriginatingAddress();                     
                    str += ":";
                    str += msgs[i].getMessageBody().toString();
                    str += "\n";
                    strNo = msgs[i].getOriginatingAddress();    
                    strMsgText = msgs[i].getDisplayMessageBody();

                }

                context.startService(new Intent(context,IncomingSMSService.class));

            }
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

}

IncomingSMSService:-

package z.z.z;

import java.util.ArrayList;

import z.z.z.Global;
import z.z.z.SMSService;

import android.app.Service;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;

public class IncomingSMSService extends Service  
{

    private String TAG = "IncomingSMSService";

    @Override
    public IBinder onBind(Intent intent)
    {
        return null;
    }

    @Override
    public void onCreate() 
    {
        /* start service */

        Log.d(TAG ,"****** in service onCreate  **----- ");
        super.onCreate();

        try
        {
            Log.d(TAG ,"****** in service try  **----- ");
            /* Read SMS from INBOX  */
            Uri uriSMSURI = Uri.parse("content://sms/inbox");      
            Cursor cur = getContentResolver().query(uriSMSURI, null, "read = 0", null,null);      
            String sms = "";      
            while (cur.moveToNext()) 
            {          
                    sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";
    //              Log.d(TAG, "in SMS Service sms in loop :: "+ sms);
            }
            Log.d(TAG, "in SMS Service sms :: "+ sms);


            Log.d(TAG ,"********** reverseNum ******  "+ Global.destNo);
            ArrayList<String> ayyMsg = new ArrayList<String>();
            ayyMsg.add(sms);
            SMSService.sendSMS(getBaseContext(), ayyMsg, Global.destNo);
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }}

SendSMS

    package z.z.z;

        import java.util.ArrayList;

        import z.z.z.common.RMAReceiver;

        import android.app.PendingIntent;
        import android.content.Context;
        import android.content.Intent;
        import android.content.IntentFilter;
        import android.telephony.SmsManager;
        import android.util.Log;

        public class SMSService 
        {

            static String TAG = "SMSService";
            static String SENT = "SMS_SENT";
            static String DELIVERED = "SMS_DELIVERED";

        //  static Context mContext;
            static RMAReceiver rmaReceiver = null;
            public static void sendSMS(Context context,ArrayList<String> message, String destNumber)
            {   
                try
                {



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

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

                    ArrayList<PendingIntent> ayySentPI = new ArrayList<PendingIntent>();
                    ayySentPI.add(sentPI);

                    ArrayList<PendingIntent> ayyDeliveredPI = new ArrayList<PendingIntent>();
                    ayyDeliveredPI.add(deliveredPI);

                    receiver(context);

                    SmsManager sms = SmsManager.getDefault();

                    sms.sendMultipartTextMessage(destNumber, null, message, ayySentPI, ayyDeliveredPI);

                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
            }

**receiver**:-

public static void receiver(Context context)
    {
        rmaReceiver = RMAReceiver.getSingleInstance();
        context.registerReceiver(rmaReceiver, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        context.registerReceiver(rmaReceiver, new IntentFilter(DELIVERED));  
    }

RMAReceiver

package z.z.z;

import z.z.z.SMSService;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.widget.Toast;

public class RMAReceiver extends BroadcastReceiver 
{
    private static RMAReceiver singleInstance = null;
    String msg;

    private RMAReceiver()
    {       
    }

    public static RMAReceiver getSingleInstance()
    {
        if(singleInstance == null) singleInstance = new RMAReceiver();
        return singleInstance;
    }

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        System.out.println("Result Code: "+getResultCode());
//      resultCode = getResultCode();
        switch (getResultCode())
        {
            case Activity.RESULT_OK:
                msg = "SMS sent/delivered";
//              Toast.makeText(context, "SMS sent/delivered", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "SMS sent/delivered", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                msg = "Generic failure";
//              Toast.makeText(context, "Generic failure", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "Generic failure", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                msg = "No service";
//              Toast.makeText(context, "No service", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                msg = "Null PDU";
//              Toast.makeText(context, "Null PDU", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                msg = "Radio off";
//              Toast.makeText(context, "Radio off", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case Activity.RESULT_CANCELED:
                msg = "SMS not delivered";
//              Toast.makeText(context, "SMS not delivered", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
        }

        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
        SMSService.sendSMS(context, msg, Global.confirmNo);



    }


}

MY LogCat Errors:-

11-16 18:26:34.661: WARN/System.err(4990): java.lang.NullPointerException
11-16 18:26:34.673: WARN/System.err(4990):     at android.os.Parcel.readException(Parcel.java:1266)
11-16 18:26:34.673: WARN/System.err(4990):     at android.os.Parcel.readException(Parcel.java:1248)
11-16 18:26:34.673: WARN/System.err(4990):     at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:526)
11-16 18:26:34.673: WARN/System.err(4990):     at android.telephony.SmsManager.sendTextMessage(SmsManager.java:109)
11-16 18:26:34.673: WARN/System.err(4990):     at android.telephony.SmsManager.sendMultipartTextMessage(SmsManager.java:263)
11-16 18:26:34.673: WARN/System.err(4990):     at z.z.z.service.SMSService.sendSMS(SMSService.java:109)
11-16 18:26:34.673: WARN/System.err(4990):     at z.z.z.receiver.IncomingSMSService.onStart(IncomingSMSService.java:64)
11-16 18:26:34.677: WARN/System.err(4990):     at android.app.Service.onStartCommand(Service.java:420)
11-16 18:26:34.677: WARN/System.err(4990):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
11-16 18:26:34.677: WARN/System.err(4990):     at android.app.ActivityThread.access$3600(ActivityThread.java:125)
11-16 18:26:34.677: WARN/System.err(4990):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
11-16 18:26:34.677: WARN/System.err(4990):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 18:26:34.677: WARN/System.err(4990):     at android.os.Looper.loop(Looper.java:123)
11-16 18:26:34.677: WARN/System.err(4990):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-16 18:26:34.677: WARN/System.err(4990):     at java.lang.reflect.Method.invokeNative(Native Method)
11-16 18:26:34.677: WARN/System.err(4990):     at java.lang.reflect.Method.invoke(Method.java:521)
11-16 18:26:34.677: WARN/System.err(4990):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
11-16 18:26:34.681: WARN/System.err(4990):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
11-16 18:26:34.681: WARN/System.err(4990):     at dalvik.system.NativeStart.main(Native Method)

Here is my code, When any message will come then my BroadCastReceiver will call. From that I started service for getting unread messages from inbox and that messages I will send as a message.

I got the message from inbox but when I send that messages as a message then I got “Nullpointer Exception”.

Please anyone can tell me at where I am wrong?

EDIT:

I found that when I send length of text in message then it will give me NullPointer Exception. As I searched on google I found that is problrm resolved by using sendMultipartTextMessage instaed of using sendTextMessage. But I already used that method so why I get this error?

Thanks.

  • 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-26T23:55:34+00:00Added an answer on May 26, 2026 at 11:55 pm

    Hello I got the solution. I feel glad to share with you people. I used

    ArrayList messages = sms.divideMessage(message);

    SmsManager sms = SmsManager.getDefault();
    ArrayList<String> messages = sms.divideMessage(message);
    sms.sendMultipartTextMessage(destNumber, null, messages, ayySentPI, ayyDeliveredPI);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this code ` // // prints out Hello World! // hello_world(); //First
I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
Hello all i got a mail code like this body = Dear & cName
Hello i`ve got a problem: when i run this code i get this: on
I've got a code like this $str = 'Hello\nThere $foo'; and I have to
I'm stuck with this pretty silly thing; I got a textfile like this; Hello::140.0::Bye
Hallo all. I got this piece of code: <div> <input id=id1 name=radioButton type=radio> <input
Hello there i got some code here; <script type=text/javascript> $(function(){ var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2&alt=json&callback=?';
Hello all this is what I got: NSN:&nbsp;<input type=text name=filterCriteria(NSN).values value=/> <input type=hidden name=filterCriteria(NSN).fieldName
Hello I got problem with scroll on my grid. Here is the code (nothing

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.