Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : SMSManager - Attempt to get length of null array [duplicate]

I have a bug from the SMSManager when I try to send a message with the method sendTextMesasge. It returns me a java.lang.NullPointerException: Attempt to get length of null array.

There is my code :

        // Constructs the message
        TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);     
        String myPhoneNumber = mTelephonyMgr.getLine1Number();
        String destNumber = taskManager.getHelpCenterNumber();
        String message = getResources().getString(R.string.call_me_message) + " " + myPhoneNumber+".";

        // Sends the message
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(destNumber, null, message, null, null);

The LogCat receives this message :

08-03 09:59:10.548: E/AndroidRuntime(19825): FATAL EXCEPTION: main
08-03 09:59:10.548: E/AndroidRuntime(19825): Process: com.solarsquareretailer.view, PID: 19825
08-03 09:59:10.548: E/AndroidRuntime(19825): java.lang.NullPointerException: Attempt to get length of null array
08-03 09:59:10.548: E/AndroidRuntime(19825):    at android.os.Parcel.readException(Parcel.java:1546)
08-03 09:59:10.548: E/AndroidRuntime(19825):    at android.os.Parcel.readException(Parcel.java:1493)
08-03 09:59:10.548: E/AndroidRuntime(19825):    at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:1428)
08-03 09:59:10.548: E/AndroidRuntime(19825):    at android.telephony.SmsManager.sendTextMessage(SmsManager.java:305)
08-03 09:59:10.548: E/AndroidRuntime(19825):    at com.solarsquareretailer.view.MainActivity.onOptionsItemSelected(MainActivity.java:245)
like image 706
Sigvent Avatar asked Mar 15 '23 05:03

Sigvent


1 Answers

Found my destNumber was null and not correct (Not a phone number). It's why I have a java.lang.NullPointerException.

like image 66
Sigvent Avatar answered Apr 27 '23 07:04

Sigvent