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. How can I achieve this menu in android?

I saw that a lot of applications has a menu at the bottom. A menu wich
is always visible.

Here you can find an example:

http://www.droid.net.au/wp-content/uploads/2010/04/Touiteur-main-screen-more.png
or
http://www.android.com/market/data/screenshots/com.cuisiner1.png

I tried to do this, with a tabHost... following the android
tutorial... But my buttons have Tab Styles...

I want to have square buttons like those ones i shown on the links...

Also i have a padding between tabs, and on the left and right side...
i wannt skip that....


Can I do what i wanna do with the tabhost? Is that possible? Does
someone has any clue?

-- 

2. Access database (in static method?) in non-Activity class

I have some class (SomeClass.class). I want to have some static
methods in it like getAllDatabaseItems, getTableItems, insertNewRecord
and so on.

If I do it this way

        SQLiteDatabase db = openOrCreateDatabase(DATABASE_NAME,
MODE_PRIVATE, null);

I need to extend Activity (but still can't use it in static methods)
or pass a "db" variable in every single method (from "caller
activity") which is pretty bulky.

What's the solution so I can from some class call
SomeClass.getAllDatabaseItems()? In short I have two classes, I have
main activity/class (which displays UI and so on) and
DatabaseOptions.java class which I should call anytime I need to (from
any other activities as well) to manipulate with my database.

User @MobileDev123 suggested me to use Context but I'm still not
getting it right...even this code isn't working.

public class Partner extends Activity {
@SuppressWarnings("static-access")
public Partner(Context mContext) {
    myContext = mContext;
    db = openOrCreateDatabase(DATABASE_NAME, myContext.MODE_PRIVATE,
null);

    db.execSQL("CREATE TABLE IF NOT EXISTS " + PARTNER_TABLE_NAME +
" (id INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " VARCHAR);");
    db.execSQL("CREATE TABLE IF NOT EXISTS " + ADDRESS_TABLE_NAME +
" (id INTEGER PRIMARY KEY AUTOINCREMENT, " + PARTNER_ID + " INT, " +
ADDRESS + " VARCHAR, " + CITY + " VARCHAR);");
}

And then call it from some of my activites like this

    Partner newPartner = new Partner(this);
    partnersItems = newPartner.getAllItems();

I get an NullExceptionError on line 4 (Partner.class) - why? If I use
static reference on

MODE_PRIVATE --> (Context.MODE_PRIVATE)

again it's not working.

-- 

3. Android proximity messaging

4. Running two Activities in Android Project

5. Licensing an Application : Android Library Projects cannot be Launched.

6. android 2.1 using usb bluetooth

7. How to creating Launcher "home screen" behavior on my app?