Hello there,

I am trying to access the contact list and display it in a CUSTOM
ListView (ListActivity is not an option). Unfortunately the activity
fails with a NullPointerException :( This may be a simple issue - have
I overlooked something ? Help appreciated ... (I have tried the code
with a ListActivity and got valid results - therefore I assume, the
Cursor instantiation is correct)

Activity Class:
---------------

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class Recommendation extends Activity
{
        //
        // GUI variables
        //
        private ListView        recommendationList;
        //
        // Logic variables
        //
        private Cursor          contacts;

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.mainmenu);
                recommendationList = (ListView) findViewById
(R.id.recommendationList);
                String[] projection = new String[] { People._ID, People.NAME,
People.PRIMARY_EMAIL_ID };
                contacts = managedQuery(Contacts.People.CONTENT_URI, projection,
null, null, null);
                SimpleCursorAdapter simpleCursorAdapter = new 
SimpleCursorAdapter
(this, android.R.layout.simple_list_item_2, contacts, new String[]
{ People.NAME, People.PRIMARY_EMAIL_ID }, new int[]
{ android.R.id.text1, android.R.id.text2 });
                recommendationList.setAdapter(simpleCursorAdapter);
        }
}

---------------

Recommendation.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"
        android:padding="10dp">
        <ListView xmlns:android="http://schemas.android.com/apk/res/android";
android:id="@+id/recommendationList"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
</LinearLayout>

---------------

LogCat:
---------------

12-08 14:30:55.852: ERROR/AndroidRuntime(4287): Uncaught handler:
thread main exiting due to uncaught exception
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{de.xxx.android/de.xxx.android.Recommendation}:
java.lang.NullPointerException
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2140)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2156)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.os.Handler.dispatchMessage(Handler.java:88)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.os.Looper.loop(Looper.java:123)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
java.lang.reflect.Method.invokeNative(Native Method)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
java.lang.reflect.Method.invoke(Method.java:515)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
dalvik.system.NativeStart.main(Native Method)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287): Caused by:
java.lang.NullPointerException
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
de.xxx.android.Recommendation.onCreate(Recommendation.java:33)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1122)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2103)
12-08 14:30:55.900: ERROR/AndroidRuntime(4287):     ... 11 more

---------------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to