找不到活动来处理Intent错误

时间:2014-04-28 23:42:08

标签: android

运行我的应用程序时,我在LogCat中收到以下错误。按下button3,callButton时发生错误。这会尝试显示要呼叫的联系人列表。它没有做任何事情,经过几次按下应用程序崩溃。

这是代码。我理解它很混乱,我正在关注一个初学的android dev。

我在这里包含清单文件; 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;
        }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我有同样的问题。当我像这样宣布意图:

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

问题解决了