0
運行我的應用程序時,LogCat中出現以下錯誤。按下按鈕3(callButton)時發生錯誤。這會嘗試調出要聯繫的聯繫人列表。它什麼都不做,並在幾次按下後,應用程序崩潰。找不到處理意圖錯誤的活動
這是代碼。我明白這是相當混亂,我跟隨一個初學者的Android開發。
我在這裏包含清單文件; http://pastebin.com/H6hw7i89
package com.example.contactpicker;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.Intents;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ContactPickerTester extends Activity {
public static final int PICK_CONTACT = 1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_picker_tester);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK, Uri
.parse("content://contacts/"));
startActivityForResult(intent, PICK_CONTACT);
}
});
Button insertContactButton = (Button) findViewById(R.id.button2);
insertContactButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insertContactWithIntent();
}
});
}
private void insertContactWithIntent() {
//inserting a new contact using intents//
Intent intent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
startActivity(intent);
Button callButton = (Button) findViewById(R.id.button3);
callButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
Intent myIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("content://contacts/"));
startActivity(myIntent);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
switch (reqCode) {
case (PICK_CONTACT): {
if (resCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
c.moveToFirst();
String name = c
.getString(c
.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
TextView tv = (TextView) findViewById(R.id.selected_contact_textview);
tv.setText(name);
}
break;
}
}
}
}