2016-01-20 19 views
-1

我正嘗試使用Intent類將我的位置發送給我的朋友。一切正常,但當我試圖發送sms.sendTextMessage時,它會引發RunTime異常。使用短信服務的運行時錯誤

>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, 
request=1, result=-1, data=Intent { 
    dat=content://com.android.contacts/contacts/lookup/2513i64a4c0af8e7588fa.1412i34 
/34 flg=0x1 }} to activity 
{com.login.thinkpad.login/com.login.thinkpad.login.SecondActivity}: 
java.lang.NullPointerException: Attempt to get length of null array 

你能幫助我如何通過短信服務發送我的位置嗎?在此先感謝。這是我的代碼。

public class SecondActivity extends AppCompatActivity { 
    TextView youLoginIn; 
    Button Map; 
    private static Intent chooser; 
    private final int PICK_CONTACT = 1; 
    @Override 
    protected void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.second_activity); 
     youLoginIn = (TextView)findViewById(R.id.youLogined); 
     Intent intent = getIntent(); 
     intent.getStringExtra("SpeicalKey"); 
     Map = (Button)findViewById(R.id.Map); 
    } 

    public void mClicked(View view){ 

     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setData(Uri.parse("google.navigation:q=a+street+address")); 
     chooser=Intent.createChooser(intent,"Launch Maps"); 

     //  if (intent.resolveActivity(getPackageManager()) != null) { 
     //   startActivity(chooser); 
     //  } 

    } 


    public void callContacts(View v) { 

     Intent intent = new Intent(Intent.ACTION_PICK,  
    ContactsContract.Contacts.CONTENT_URI); 
     startActivityForResult(intent, PICK_CONTACT); 
    } 

    @Override 
    protected void onActivityResult(int reqCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(reqCode, resultCode, data); 

     if(reqCode == PICK_CONTACT) { 
      if(resultCode == ActionBarActivity.RESULT_OK) { 
       Uri contactData = data.getData(); 
       Cursor c = getContentResolver().query(contactData, null, null, null, null); 

       if(c.moveToFirst()) { 
        String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); 
        Toast.makeText(this, "You've picked:" + name, Toast.LENGTH_LONG).show(); 

        //send your location to that name choosen. 
        SmsManager sms = SmsManager.getDefault(); 
        sms.sendTextMessage(name,null, String.valueOf(chooser),null,null); // Exception occur here. 
       } 
      } 
     } 
    } 

} 

回答

0
+0

這不是我期待的。 –

+0

公衆最終無效sendDataMessage(串目的地地址,字符串scAddress,短destinationPort,字節[]數據的PendingIntent sentIntent,的PendingIntent deliveryIntent) 目的地地址\t將消息發送到 上的地址是人不是名字,你的電話號碼得到 ContactsContract.Contacts.DISPLAY_NAME – user1820553

+0

是的,這是真的。我剛剛解決了。謝謝。 –