从ListView问题进行调用

时间:2013-01-12 22:53:01

标签: java android listview

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

有人能指出我如何在清单中编写意图动作的正确方向吗?

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

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)

我的视图类用于设置listview,最后用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;

    }

1 个答案:

答案 0 :(得分:0)

您忘了拨打open()again。 :)

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

如果你使data成为一个字段变量,你可以从任何方法访问它,而不需要创建一个新的DBHandler。