嗨,我的主要问题是向选定的目的地地址发送短信。大多不止一个。选择工作正常,但发送短信的方法总是显示 NullPointerException,我无法找到主要错误。emerNames 是一个简单的字符串数组,emerNumbers 也是如此!在我看来要发送的文本不是问题,但可能是在 for 循环中使用数组的发送操作!
有什么建议么?
AlertDialog.Builder settingMessage = new AlertDialog.Builder(c);
settingMessage.setTitle("SOS- Empfänger wählen");
settingMessage.setMultiChoiceItems(emerNames, checkItem, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked)
{
if (isChecked == true)
{
Log.i("AlertChoice", "SelectedItem: "+emerNames[which]);
ischecked[which] = true;
//emerNumbers[which]=emerNames[which];
}
else
{
ischecked[which]=false;
//emerNumbers[which]= "";
Log.i("AlertChoice", "Deseclected Item "+emerNames[which]);
}
}
} );
settingMessage.setNeutralButton("SOS senden", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
for (int i = 0; i<ischecked.length;i++)
{
if (ischecked[i]== true)
{
Log.i("Selection", "SelectedItems:"+ emerNumbers[i]);
String text;
text = "HILFE, ich befinde mich in einer Notlage\n"
+"Meine persönlichen Daten:\n"
+"Vorname: "+empersData[0]+"\n"
+"Zuname: "+empersData[1]+"\n"
+"Alter: "+empersData[2]+"\n"
+"Blutgruppe: "+empersData[3]+empersData[4]+"\n";
/*+"Versicherungsnr: "+empersData[5]+"\n"
+"Geschlecht: "+empersData[6]+"\n";*/
SmsManager sms = SmsManager.getDefault();
Log.i("nr","Telefonnr 1: "+ emerNumbers[i]);
Log.i("text",text);
sms.sendTextMessage(emerNumbers[i], null, text, null, null);
//Toast.makeText(this, "SOS versendet", Toast.LENGTH_LONG).show();
Log.i("onClickTest", "Überprüfung Index: "+ischecked[i]);
方法“sms.sendTextMessage”抛出 NullPointerException!