0

Im attempting to make a call when i click on a item in my listview. I pass the given id in the onListItemClick method to a handler in my database class that retrieve s the number and sets it in my intent. When the item is clicked it then crashes.

Can someone point me in the right direction of how to write the intent action in the manifest?

My log cat gives the errors as shown:

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)

Heres my view class used to setup the listview, and the onlick method at the end to call the number:

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);  

}
}

And the method used in my database handler class to retrieve the number stored at the database based on the passed 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

You forgot to call open(), again. :)

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

If you make data a field variable you could access it from any method and wouldn't need to create a new DBHandler.

于 2013-01-12T22:55:11.943 に答える