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)
Found my destNumber was null and not correct (Not a phone number). It's why I have a java.lang.NullPointerException.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With