2011-06-14 187 views
6

我得到這個錯誤從我的用戶之一,我有)不知道如何解決它......拋出:IllegalArgumentException readExceptionFromParcel

java.lang.IllegalArgumentException異常 DatabaseUtils.readExceptionFromParcel(

java.lang.IllegalArgumentException: URI: content://com.android.contacts/phone_lookup/, calling user: com.piroja.contactpicker, calling package:com.piroja.contactpicker at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144) 
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) 
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330) 
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366) 
at android.content.ContentResolver.query(ContentResolver.java:245) 
at com.piroja.contactpicker.ContactPicker.contactExists(ContactPicker.java:257) 
at com.piroja.contactpicker.ContactPicker$6$1.onClick(ContactPicker.java:138) 
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:123) 
at android.app.ActivityThread.main(ActivityThread.java:4627) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:521) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
at dalvik.system.NativeStart.main(Native Method) 

這是聯繫我們funcion我打電話給哪個(我認爲)導致這個部隊關閉:

public boolean contactExists(Context context, String number) { 
     try { 
      Uri lookupUri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri 
        .encode(number)); 
      String[] mPhoneNumberProjection = { Phone._ID, Phone.NUMBER, 
        Phone.DISPLAY_NAME }; 
      Cursor cur = context.getContentResolver().query(lookupUri, 
        mPhoneNumberProjection, null, null, null); 
      try { 
       if (cur.moveToFirst()) { 
        return true; 
       } 
      } finally { 
       if (cur != null) 
        cur.close(); 
      } 
     } catch (IllegalArgumentException iae) { 
      return false; 
     } 
     return false; 
    } 

我也試圖改變Phone.CONTENT_ FILTER_URI到PhoneLookup.CONTENT_FILTER_URI,但它沒有改變任何東西......有沒有人有線索?

回答

11

電話查詢URI存在問題。從例外文本看起來它缺少電話號碼。你確定號碼不是空的,而不是空的?

+0

我試過了幾個不同的聯繫人。與名稱和號碼,只有名稱,只有號碼...在我的慾望什麼也沒有發生......因爲我沒有看到這些用戶有什麼電話,我不能真正告訴你如何創建錯誤或在哪些手機上崩潰。 – user754730 2011-06-15 08:44:17

+0

任何想法的人?有沒有解決方法或什麼? – user754730 2011-06-20 12:33:05

+0

從日誌「content://com.android.contacts/phone_lookup/」中找不到電話號碼。在方法開始時加一個斷言來防止空或空的電話號碼 – 2011-06-21 02:42:23

1

我不知道是否有人仍然需要這個答案,但我試過,直到我得到它。問題是,有時,當您擴展PhoneStateListener類或傳遞最後一個來電號碼時,來電號碼爲null。我改變了我的代碼,這一點,它工作得很好

@Override 
public void onReceive(final Context context, final Intent intent) { 
    Log.d("APP", "ACTION:" + intent.getAction()); 
    final String stringExtra = intent.getStringExtra(TelephonyManager.EXTRA_STATE); 
    if (TelephonyManager.EXTRA_STATE_RINGING.equals(stringExtra)) { 
      final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      Log.d("APP", "incoming,ringing:" + incomingNumber); 
     } else if (stringExtra.equals(TelephonyManager.EXTRA_STATE_IDLE)) { 
      final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      Log.d("APP", "hanged" + incomingNumber); 
     } else if (stringExtra.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { 
      final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      Log.d("APP", "answered" + incomingNumber); 
     } 
    } 

...這個解決方案是here

相關問題