0

我希望用来String aa=c.getString(c.getColumnIndex("address"))获取函数中某项的列值private void SetSelectedAndTotal
但是应用程序崩溃了,我该怎么办?谢谢!

private ListView lv; 
private TextView selectedAndTotal;

private void InitListView() {
    List<String> msgList = getSMS();
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice, msgList);
    lv.setAdapter(adapter2);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            SetSelectedAndTotal(arg2);
        }
    });
}

private void SetSelectedAndTotal(int arg2){     
    Cursor c = (Cursor) lv.getItemAtPosition(arg2);
    String aa=c.getString(c.getColumnIndex("address"));
    selectedAndTotal.setText(aa);       
}


public List<String> getSMS() {
    List<String> sms = new ArrayList<String>();
    Uri uriSMSURI = Uri.parse("content://sms/inbox");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,
            null);

    while (cur.moveToNext()) {
        String address = cur.getString(cur.getColumnIndex("address"));
        String body = cur.getString(cur.getColumnIndexOrThrow("body"));
        sms.add("Number: " + address + " .Message: " + body);

    }
    return sms;
}
4

1 回答 1

0
String aa=c.getString(c.getColumnIndex("address"));
selectedAndTotal.setText(aa); 

如果不存在这样的列,则返回-1. 最有可能发生这种情况,并且您传递了一个整数作为参数,该参数被视为资源 ID。

另外,请确保您TextViewsetText().

于 2013-05-19T14:07:39.170 回答