0

当我单击列表视图中的项目时,我试图拨打电话。我将方法中的给定 id 传递给 onListItemClick我的数据库类中的处理程序,该处理程序检索数字并将其设置在我的意图中。单击该项目时,它会崩溃。

有人可以指出如何在清单中编写意图操作的正确方向吗?

我的日志猫给出了如下所示的错误:

01-12 23:03:06.799: E/AndroidRuntime(276): FATAL EXCEPTION: main
01-12 23:03:06.799: E/AndroidRuntime(276): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=Contact No:01406 330611 }
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.Activity.startActivityForResult(Activity.java:2817)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.Activity.startActivity(Activity.java:2923)
01-12 23:03:06.799: E/AndroidRuntime(276):  at com.example.flybase2.view.onListItemClick(view.java:50)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.ListActivity$2.onItemClick(ListActivity.java:321)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.widget.ListView.performItemClick(ListView.java:3382)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.os.Handler.handleCallback(Handler.java:587)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.os.Looper.loop(Looper.java:123)
01-12 23:03:06.799: E/AndroidRuntime(276):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-12 23:03:06.799: E/AndroidRuntime(276):  at java.lang.reflect.Method.invokeNative(Native Method)
01-12 23:03:06.799: E/AndroidRuntime(276):  at java.lang.reflect.Method.invoke(Method.java:521)
01-12 23:03:06.799: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-12 23:03:06.799: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-12 23:03:06.799: E/AndroidRuntime(276):  at dalvik.system.NativeStart.main(Native Method)

这是我用来设置列表视图的视图类,以及最后的 onlick 方法来调用号码:

package com.example.flybase2;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.ListView;

public class view extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactlayout);

    DBHandler DBref = new DBHandler(this, null, null);

    ListView listContent = (ListView)findViewById(android.R.id.list);


    DBHandler data = new DBHandler(this, null, null);
    data.open();
    Cursor cursor = data.getData();
    startManagingCursor(cursor);

    @SuppressWarnings("static-access")
    String [] from = new String [] {DBref.KEY_NAME, DBref.KEY_TEL, DBref.KEY_EMAIL, DBref.KEY_COMMENTS};
    int [] to = new int [] {R.id.txtNameList, R.id.txtTelList, R.id.txtEmailList, R.id.txtCommentsList};

    @SuppressWarnings("deprecation")
    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.setlistviewcontacts, cursor, from, to);

    listContent.setAdapter(cursorAdapter);

}


public void onListItemClick(ListView list, View v, int list_posistion, long item_id)
{
    long idToPass = item_id;
    DBHandler num = new DBHandler(this, null, null);

    String numReturned = num.getNum(idToPass);

    Intent makeCall = new Intent(Intent.ACTION_CALL, Uri.parse("Contact No:" + numReturned));
       startActivity(makeCall);  

}
}

我的数据库处理程序类中使用的方法根据传递的 ID 检索存储在数据库中的数字:

public String getNum(long passId) {
        String [] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_TEL, KEY_EMAIL, KEY_COMMENTS};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + passId, null, null, null, null);
        if(c != null)
        {
            // move to the selected row
        c.moveToFirst();
        String num = c.getString(2);
        return num;

    }
        return null;

    }
4

1 回答 1

0

你又忘记打电话open()了。:)

DBHandler num = new DBHandler(this, null, null);
num.open();

如果您创建data一个字段变量,您可以从任何方法访问它,而无需创建新的 DBHandler。

于 2013-01-12T22:55:11.943 回答