无法理解此联系人应用程序 logcat

Posted

技术标签:

【中文标题】无法理解此联系人应用程序 logcat【英文标题】:Can't understand this contact app logcat 【发布时间】:2013-06-19 15:05:20 【问题描述】:

我仍然习惯于查看 logcat。我正在创建一个联系人应用程序来学习 android 开发,当我尝试加载此联系人信息时出现错误。如果可以的话,请解释一下这个 logcat,这样我就有机会更好地理解如何阅读它们。它正在尝试检索联系人 ID = 3 的信息。在此先感谢

代码:

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

日志猫:

java.lang.IllegalArgumentException: Invalid column data1
        at android.database.sqlite.SQLiteQueryBuilder.computeProjection(SQLiteQueryBuilder.java:632)
        at android.database.sqlite.SQLiteQueryBuilder.buildQuery(SQLiteQueryBuilder.java:447)
        at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:387)
        at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:6043)
        at com.android.providers.contacts.ContactsProvider2.queryLocal(ContactsProvider2.java:6019)
        at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:4787)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:113)
        at android.os.Binder.execTransact(Binder.java:351)
        at dalvik.system.NativeStart.run(Native Method)
06-22 13:25:47.673  15139-15246/sat.tuts4mobile.customlistview E/AndroidRuntime: FATAL EXCEPTION: Thread-639
        java.lang.IllegalArgumentException: Invalid column data1
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
        at android.content.ContentResolver.query(ContentResolver.java:372)
        at android.content.ContentResolver.query(ContentResolver.java:315)
        at sat.tuts4mobile.customlistview.ContactDetails$1.run(ContactDetails.java:51)
        at java.lang.Thread.run(Thread.java:856)

【问题讨论】:

根据 logcat no such column: contact_id1 进行一些更改。更新了代码并发布了新的 logcat 【参考方案1】:

根据logcat,错误是:no such column: contact_id1

这是因为您忘记了这一行中的=

ContactsContract.Data.CONTACT_ID + contactId

这给出了contact_id1 而不是contact_id = 1。应该是:

ContactsContract.Data.CONTACT_ID + " = " + contactId

【讨论】:

谢谢你。更改后,我收到另一个错误。编辑了我原来的帖子。如果/当你有机会时,请看看。 很高兴它对您有所帮助,但如果您有其他问题,您应该发布另一个问题(我不知道答案,抱歉)。 它发生了。感谢您的帮助

以上是关于无法理解此联系人应用程序 logcat的主要内容,如果未能解决你的问题,请参考以下文章

Cordova - 由于联系权限,Android 应用程序在启动时崩溃

无法让 logcat 工作 android studio

Logcat 说“无效的列 data1”

Logcat 错误运行时异常,无法启动活动

Android 如何发送多个联系人附加在单个 .vcf 文件中并发送到邮件?

Android WiFi 调试 -> Logcat