我想要顯示的聯繫人姓名和它在以這種方式複選框電話號碼顯示聯繫人和電話號碼:「聯繫人姓名:電話號碼」 但我發現這個錯誤的logcat的"java.lang.IllegalArgumentException: Invalid column data1"
複選框中
這裏是我----->
package wael.ilahi.pfe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.zip.Inflater;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
...
public class SelectFriends extends Activity implements OnClickListener {
public static final String TAG = "ContactManager";
private Button bSave;
private ListView lv;
private boolean mShowInvisible;
CheckBox ch;
String s;
int k=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.v(TAG, "Activity State: onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
bSave = (Button) findViewById(R.id.addContactButton);
lv = (ListView) findViewById(R.id.contactList);
populateContactList();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,final
int position, long id) {
ch = (CheckBox) view.findViewById(R.id.checkBox);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + position, Toast.LENGTH_LONG).show();
}
});
}
});
bSave.setOnClickListener(this);
}
private void populateContactList() {
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] {
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME +":"+
ContactsContract.CommonDataKinds.Phone.NUMBER};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.contact_entry, cursor,fields, new int[] {R.id.checkBox});
lv.setAdapter(adapter);
}
private Cursor getContacts(){
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
//ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER };
String selection = null;
String[] selectionArgs = null;
String sortOrder =null;
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
將完整的StackTrace添加到您的問題。 – 2012-02-23 21:48:48