Problem with a contacts viewer

by jamul » Sat, 20 Dec 2008 10:54:56 GMT


Sponsored Links
 Hi,

I'm just getting problems with my app'... and really don't understand
all about that.
When I launch my ListActivity I get : "XContacts has stopped
unexpectedly"

XContacts is just a list view of contacts which are saved in phone.
Here is the code, I hope that I'll get some responses because I'm
thinking that I haven't understood something in documentation...


--
XContacts.java
--
package com.test.xcontacts;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class XContacts extends ListActivity {
        private String[] _projection = new String[] {
                    People.NAME
                };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_list);

        Cursor managedCursor = managedQuery(People.CONTENT_URI,
                                _projection,
                                null,
                                null,
                                People.NAME + " ASC");

        String[] from = new String[] {
                        People.NAME
        };

        int[] to = new int[] {
                        R.id.text1
        };

        ListAdapter contactsAdapter =
                        new SimpleCursorAdapter(this, 
R.layout.contacts_list_row,
managedCursor, from, to);
        setListAdapter(contactsAdapter);
    }
}


--
contacts_list.xml
--
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <ListView android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
  <TextView android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_contacts"/>

</LinearLayout>


--
contacts_list_row
--
<?xml version="1.0" encoding="UTF-8"?>
<TextView android:id="@+id/text1"
    xmlns:android=" http://schemas.android.com/apk/res/android" ;
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

--~--~---------~--~----~------------~-------~--~----~



Problem with a contacts viewer

by Mark Murphy » Sat, 20 Dec 2008 23:25:40 GMT


 


Have you looked at the log output (e.g., adb logcat) to see what errors 
you are getting?

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.9 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Problem with a contacts viewer

by jamul » Sun, 21 Dec 2008 04:31:08 GMT


 Hmm finally I looked at it and resolved my problem.
That was my projection which causes that.
I just added People._ID and that worked :)

Thanks for your help, and hope that can serve to others having same
problems.





--~--~---------~--~----~------------~-------~--~----~



Problem with a contacts viewer

by tek » Sun, 01 Feb 2009 08:10:51 GMT


 Ah you helped me fix it anyway.... Exception browser wasn't showing
any errors so I had nothing to go off of.

My issue was android:id was set to "@+id/list", changed this to
"@android:id/list" and it fixed it.







--~--~---------~--~----~------------~-------~--~----~



Problem with a contacts viewer

by tek » Sun, 01 Feb 2009 08:10:51 GMT


 Why even post that you fixed it if you aren't going to give any
details? What a waste of your time _and_ mine. Where did you add the
like People._ID?









--~--~---------~--~----~------------~-------~--~----~



Problem with a contacts viewer

by anderson » Thu, 05 Mar 2009 21:38:49 GMT


 i have problem with managedQuery ,too.

from document we know Parameters :

uri                The URI of the content provider to query.
projection         List of columns to return.
selection          SQL WHERE clause.
selectionArgs   The arguments to selection, if any ?s are pesent
sortOrder               SQL ORDER BY clause.


i want to query the contact, select  whose name is User and show the
id
how do i write the query string ??

i thought maybe :

 String queryResult[]= new String[] {People._ID};
 String queryStr = People.NUMBER + " is not null and " + People.NAME +
"="+"User";

         Cursor c = getContentResolver().query(
                         People.CONTENT_URI,
                         queryResult,
                         querystr,
                         null,
                         People.DISPLAY_NAME + " asc");

but the error log :

03-05 13:31:52.736: ERROR/DatabaseUtils(90):
android.database.sqlite.SQLiteException: no such column: User: ,
while compiling: SELECT people._id AS _id FROM people LEFT OUTER JOIN
phones ON people.primary_phone=phones._id LEFT OUTER JOIN presence ON
 (presence.person=people._id) WHERE (name=Anderson) ORDER BY
display_name asc

can anyone explain this error log ?

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Please add the Azerbaijani Language to LatinIME

I would do it myself but it seems that the only way to do development
on the Android project is via Linux and I'm running Eclipse on Windows
7 64-bit.  It's a basic latin alphabet that doesn't require more than
a handful of special characters.  I'll gladly provide links to the
keyboard layout.

-- 

2. Cloud API for content extraction

I am thinking of developing a cloud service to allow app developers to
inject Javascript to web pages and retrieve JSON/XML/HTML from any web
page.

Is this something that is needed for mobile apps?

-- 

3. Android Accelerometer + Orientation

4. Making Sure a Finished App is not Draining Resources

5. Adding swype-like functionality to the LatinIME keyboard

6. Can we register our device without having third party server?

7. Begginer list view issue