content:// mms-sms / conversations /在Android ICS Samsung上返回NullPointerException

时间:2012-10-17 02:15:31

标签: android sms uri android-contentprovider

我正在开发短信应用程序,需要列出短信对话。尝试使用uri content://mms-sms/conversations/访问内容提供商时发现了问题。它在Android 2.3上运行良好,但在Android 4.0.3三星galaxy tab 2上运行时会返回错误:

 10-17 09:04:51.035: E/AndroidRuntime(22600): FATAL EXCEPTION: main
 10-17 09:04:51.035: E/AndroidRuntime(22600):
 java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.yooi/com.yooi.ui.MainActivity}:
 android.view.InflateException: Binary XML file line #6: Error
 inflating class fragment 10-17 09:04:51.035: E/AndroidRuntime(22600):
    at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.access$600(ActivityThread.java:128) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.os.Handler.dispatchMessage(Handler.java:99) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.os.Looper.loop(Looper.java:137) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.app.ActivityThread.main(ActivityThread.java:4514) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 java.lang.reflect.Method.invokeNative(Native Method) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 java.lang.reflect.Method.invoke(Method.java:511) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 dalvik.system.NativeStart.main(Native Method) 10-17 09:04:51.035:
 E/AndroidRuntime(22600): Caused by: android.view.InflateException:
 Binary XML file line #6: Error inflating class fragment 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:489) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:396) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:352) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.Activity.setContentView(Activity.java:1835) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.yooi.ui.MainActivity.onCreate(MainActivity.java:17) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.Activity.performCreate(Activity.java:4465) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   ... 11 more 10-17
 09:04:51.035: E/AndroidRuntime(22600): Caused by:
 java.lang.NullPointerException 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.os.Parcel.readException(Parcel.java:1334) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.content.ContentResolver.query(ContentResolver.java:311) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.yooi.ui.SmsThreadListActivity.getThreadListCursor(SmsThreadListActivity.java:146)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 com.yooi.ui.SmsThreadListActivity.onCreateView(SmsThreadListActivity.java:95)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:806)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1010)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1108)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.Activity.onCreateView(Activity.java:4243) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   ... 21 more

我花了我的时间在谷歌搜索但仍然没有找到答案。知道的任何人请帮助我,我为这个恼人的问题而烦恼:(

1 个答案:

答案 0 :(得分:6)

可以通过此查询检索对话列表:

Uri.parse("content://mms-sms/conversations?simple=true"); 
Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);

此处的关键点是URI content://mms-sms/conversations?simple=true

here