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. Avoiding compression on large files

Apparently you can't have a file in "assets" larger than 1MB (except
for certain file types) because it's considered too large to
uncompress.

But I'm finding mixed info about how to circumvent this limitation.
Some say that you can put the files in "raw" and avoid the limitation
but others say that files in "raw" are compressed too.  And there's
the -0 aapt option that can be used to turn off compression for
certain file types, but there's no way to specify aapt options in
Carbide.

I realize that I can break the file into pieces, but that's error-
prone on both ends.  And using one of the known uncompressed file
types not only confuses things but also runs the risk that the Android
PTB will decide to start compressing that file type.

So what are my options really?

-- 

2. Can I post text to facebook profile from my android application?

Hi Friends,


This is Rockson,
I am new to android. Here i am struggling with facebook posts from
android application.

I am developing a application in android from which i want to post
some text to my facebook profile.

Can i do that? Please help me.


Thanks and Regards,

Kiran.


-- 

3. Cannot install apk of huge size

4. VLC RTSP MPEG-4 stream to Android emulator.

5. Cannot share audio file by MMS, and how to solve this case?

6. loading an html file from local res directory

7. settings - is this a ListView ?