LogCat中说,"无效的列数据1" [英] Logcat says "invalid column data1"
问题描述
新到线程。新来的SQL。新来获取联系方式。所以,当然,我迷路了。如果我正确地阅读本logcat的,它告诉我,或者:列数据1不存在,或者说我找错了信息。不幸的是,这一直是学习的学习从我的错误的路径,我不明白这一个。任何帮助是非常AP preciated。
这里的目标是获得了姓名,电话号码和电子邮件联系人的(与之相匹配的联系人ID信息)。
日志:
06-22 21:15:44.700:E / AndroidRuntime(1662年):致命异常:螺纹120
06-22 21:15:44.700:E / AndroidRuntime(1662年):java.lang.IllegalArgumentException异常:无效的列数据1
06-22 21:15:44.700:E / AndroidRuntime(1662年):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在android.content.ContentResolver.query(ContentResolver.java:372)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在android.content.ContentResolver.query(ContentResolver.java:315)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在sat.tuts4mobile.customlistview.ContactDetails $ 1.运行(ContactDetails.java:53)
06-22 21:15:44.700:E / AndroidRuntime(1662年):在java.lang.Thread.run(Thread.java:856)
code(它拉的接触式ID 0资讯):
进口android.app.Activity;
进口android.database.Cursor;
进口android.net.Uri;
进口android.os.Bundle;
进口android.provider.ContactsContract;
进口android.widget.TextView;
/ **
*在13年6月19日创建者皮特。
* /
公共类ContactDetails延伸活动{
TextView的tvContactName,tvPhoneNum,tvPhoneType,tvPhoneFull,
tvEmailAdd,tvEmailType,tvEmailFull,
tvAddress,tvAddType,tvAddFull;
字符串的ContactID,联系人姓名,phoneType,phoneFull,phoneNum1,
emailAdd,emailType,emailFull,
地址的addType,addFull;
//联系人列表查询参数
乌里URI;
的String []投影,selectionArgs两个;
串选择,排序顺序;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.contactinfo);
初始化();
使用ContactID = getIntent()getStringExtra(的ContactID)。
联系人姓名= getIntent()getStringExtra(联系人姓名)。
新主题(新的Runnable(){
@覆盖
公共无效的run(){
URI = ContactsContract.Contacts.CONTENT_URI;
投影=新的String [] {
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
选择= ContactsContract.Data.CONTACT_ID +
=+的ContactID +和+
ContactsContract.Data.MIMETYPE +=+
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE +';
selectionArgs两个= NULL;
排序顺序= NULL;
//创建光标搜索与使用ContactID相关数据
如果(使用ContactID!= NULL){
//返回所有的电话数据的联系人
光标光标= getContentResolver()查询(
URI,投影,选择,selectionArgs两个,排序顺序);
//获取所需的列的索引
而(cursor.moveToNext()){
//提取名称
联系人姓名= cursor.getString(
cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
tvContactName.setText(联系人姓名);
//提取电话号码
phoneFull = cursor.getString(
cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
tvPhoneFull.post(新的Runnable(){
@覆盖
公共无效的run(){
// TODO自动生成方法存根
tvPhoneFull.setText(phoneFull);
}
});
cursor.close();
}
}
})。开始();
新主题(新的Runnable(){
@覆盖
公共无效的run(){
URI = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
投影=无效;
选择= ContactsContract.CommonDataKinds.Email.CONTACT_ID +
=+的ContactID +和+
ContactsContract.Data.MIMETYPE +=+
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE +';
selectionArgs两个= NULL;
排序顺序= NULL;
光标emailCursor = getContentResolver()查询(
URI,投影,选择,selectionArgs两个,排序顺序);
而(emailCursor.moveToNext()){
//提取电子邮件地址
emailFull = emailCursor.getString(
emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
tvPhoneFull.post(新的Runnable(){
@覆盖
公共无效的run(){
tvEmailFull.setText(emailFull);
}
});
emailCursor.close();
}
})。开始();
}
公共无效初始化(){
tvContactName =(TextView中)findViewById(R.id.tvContactName);
tvPhoneNum =(TextView中)findViewById(R.id.tvPhoneNum);
tvPhoneType =(TextView中)findViewById(R.id.tvPhoneType);
tvPhoneFull =(TextView中)findViewById(R.id.tvPhoneFull);
tvEmailAdd =(TextView中)findViewById(R.id.tvEmailAdd);
tvEmailType =(TextView中)findViewById(R.id.tvEmailType);
tvEmailFull =(TextView中)findViewById(R.id.tvEmailFull);
tvAddress =(TextView中)findViewById(R.id.tvAddress);
tvAddType =(TextView中)findViewById(R.id.tvAddType);
tvAddFull =(TextView中)findViewById(R.id.tvAddFull);
}
}
要获取电话号码,查询 Phone.CONTENT_URI
,包括 Phone.NUMBER
在你的投影。
要检索电子邮件地址,查询 Email.CONTENT_URI
,并要求 Email.DATA
在你的投影。
无论这些也将让你包括 Contacts.DISPLAY_NAME
在你的投影为好,如一些常见的栏目一样,都自动加入。
虽然我还没有检索到该数据由ID之前,我相信你的WHERE子句将 Phone.CONTACT_ID +=+的ContactID
和<$ C > Email.CONTACT_ID +=+的ContactID 分别为$ C。请参见如何获取联系人的电话号码,在Android中了解更多
New to threading. New to SQL. New to getting Contact Info. So of course I'm lost. If I'm reading this logcat correctly, it's telling me that either: column data1 doesn't exist, or that I'm looking for the wrong info. Unfortunately, this has been a "learn from my mistakes" path of learning and I can't figure this one out. Any help is very much appreciated.
The goal here is to get the Name, Phone Number, and Email of the contact (matching info by contact ID).
Log:
06-22 21:15:44.700: E/AndroidRuntime(1662): FATAL EXCEPTION: Thread-120
06-22 21:15:44.700: E/AndroidRuntime(1662): java.lang.IllegalArgumentException: Invalid column data1
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentResolver.query(ContentResolver.java:372)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentResolver.query(ContentResolver.java:315)
06-22 21:15:44.700: E/AndroidRuntime(1662): at sat.tuts4mobile.customlistview.ContactDetails$1.run(ContactDetails.java:53)
06-22 21:15:44.700: E/AndroidRuntime(1662): at java.lang.Thread.run(Thread.java:856)
Code (It's pulling info for contact ID 0):
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;
/**
* Created by Pete on 6/19/13.
*/
public class ContactDetails extends Activity {
TextView tvContactName, tvPhoneNum, tvPhoneType, tvPhoneFull,
tvEmailAdd, tvEmailType, tvEmailFull,
tvAddress, tvAddType, tvAddFull;
String contactId, contactName, phoneType, phoneFull, phoneNum1,
emailAdd, emailType, emailFull,
address, addType, addFull;
//Contact List query arguments
Uri uri;
String[] projection, selectionArgs;
String selection, sortOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contactinfo);
initialize();
contactId = getIntent().getStringExtra("contactId");
contactName = getIntent().getStringExtra("contactName");
new Thread(new Runnable() {
@Override
public void run() {
uri = ContactsContract.Contacts.CONTENT_URI;
projection = new String[] {
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
selection = ContactsContract.Data.CONTACT_ID +
" = " + contactId + " AND " +
ContactsContract.Data.MIMETYPE + " = '" +
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'";
selectionArgs = null;
sortOrder = null;
// Create cursor searching for data associated with contactId
if (contactId != null) {
// Return all the PHONE data for the contact
Cursor cursor = getContentResolver().query(
uri, projection, selection, selectionArgs, sortOrder);
//Get the indexes of the required columns
while (cursor.moveToNext()) {
// Extract the name
contactName = cursor.getString(
cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
tvContactName.setText(contactName);
// Extract the phone number
phoneFull = cursor.getString(
cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
tvPhoneFull.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tvPhoneFull.setText(phoneFull);
}
});
cursor.close();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
projection = null;
selection = ContactsContract.CommonDataKinds.Email.CONTACT_ID +
" = " + contactId + " AND " +
ContactsContract.Data.MIMETYPE + " = '" +
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'";
selectionArgs = null;
sortOrder = null;
Cursor emailCursor = getContentResolver().query(
uri, projection, selection, selectionArgs, sortOrder);
while (emailCursor.moveToNext()) {
// Extract email address
emailFull = emailCursor.getString(
emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
tvPhoneFull.post(new Runnable() {
@Override
public void run() {
tvEmailFull.setText(emailFull);
}
});
emailCursor.close();
}
}).start();
}
public void initialize() {
tvContactName = (TextView)findViewById(R.id.tvContactName);
tvPhoneNum = (TextView)findViewById(R.id.tvPhoneNum);
tvPhoneType = (TextView)findViewById(R.id.tvPhoneType);
tvPhoneFull = (TextView)findViewById(R.id.tvPhoneFull);
tvEmailAdd = (TextView)findViewById(R.id.tvEmailAdd);
tvEmailType = (TextView)findViewById(R.id.tvEmailType);
tvEmailFull = (TextView)findViewById(R.id.tvEmailFull);
tvAddress = (TextView)findViewById(R.id.tvAddress);
tvAddType = (TextView)findViewById(R.id.tvAddType);
tvAddFull = (TextView)findViewById(R.id.tvAddFull);
}
}
To retrieve phone numbers, query Phone.CONTENT_URI
and include Phone.NUMBER
in your projection.
To retrieve email addresses, query Email.CONTENT_URI
and ask for Email.DATA
in your projection.
Either of those will also allow you to include Contacts.DISPLAY_NAME
in your projection as well, as some common columns like that are automatically joined in.
While I have not retrieved this data by ID before, I believe that your "where clause" would be Phone.CONTACT_ID + " = " + contactId
and Email.CONTACT_ID + " = " + contactId
respectively. See How to get contacts' phone number in Android for more.
这篇关于LogCat中说,&QUOT;无效的列数据1&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!