use the "String selection = People.NUMBER + "= ?" + telNo;"replace !



[EMAIL PROTECTED]
2008年10月16日 
----- Original Message ----- 
From: vallis 
To: Android Developers 
Sent: 2008-10-13, 23:37:59
Subject: [android-developers] nullPointer/thread error when reading contacts


Hi all,
I've been trying to read the contacts list so that I can compare phone
numbers in it against the number on an incomming SMS message.
I've been getting an error that I just can't fix.

The method is:
public String checkContacts(String telNo)
    {
      String[] projection = new String[] {People.NAME, People.NUMBER};
      Uri mContacts = People.CONTENT_URI;
      String selection = People.NUMBER + "=" + telNo;
      String sort = People.NAME + " ASC";

      Cursor managedCursor = managedQuery(mContacts, projection,
selection, null, sort);
      startManagingCursor(managedCursor);

      if(managedCursor.getCount() > 0)
      {
        managedCursor.moveToFirst();
        return managedCursor.getString(0);
      }
      else
      {
        return telNo;
      }
    }

Output from LogCat looks like this:
10-13 16:37:35.966: DEBUG/AndroidRuntime(292): Shutting down VM
10-13 16:37:35.966: WARN/dalvikvm(292): threadid=3: thread exiting
with uncaught exception (group=0x40010e28)
10-13 16:37:35.976: ERROR/AndroidRuntime(292): Uncaught handler:
thread main exiting due to uncaught exception
10-13 16:37:35.996: ERROR/AndroidRuntime(292):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{napier.vallis/napier.vallis.SMSClient}:
java.lang.NullPointerException
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2140)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2156)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.os.Handler.dispatchMessage(Handler.java:88)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.os.Looper.loop(Looper.java:123)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread.main(ActivityThread.java:3742)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
java.lang.reflect.Method.invokeNative(Native Method)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
java.lang.reflect.Method.invoke(Method.java:515)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:739)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
dalvik.system.NativeStart.main(Native Method)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): Caused by:
java.lang.NullPointerException
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.content.ContextWrapper.getContentResolver(ContextWrapper.java:
89)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.Activity.managedQuery(Activity.java:1442)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
napier.vallis.Functions.checkContacts(Functions.java:70)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
napier.vallis.SMSClient.onCreate(SMSClient.java:34)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1122)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2103)
10-13 16:37:35.996: ERROR/AndroidRuntime(292): ... 11 more

If any further information is needed I can easily post it up.

Any advice or guidance would be greatly appreciated.
Thanks,

V.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
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