2015-12-03 69 views
0

我試圖運行示例代碼在Android 1.5模擬器啓動應用程序時,我得到了這些錯誤....任何一個有一些提示..?從logcat的 錯誤:關於android studio活動的錯誤?

12-03 08:17:41.221 2141-2141/com.example.umairkhan.test1 E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.example.umairkhan.test1, PID: 2141 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.umairkhan.test1/com.example.umairkhan.test1.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{b3e8b0d 2141:com.example.umairkhan.test1/u0a57} (pid=2141, uid=10057) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{b3e8b0d 2141:com.example.umairkhan.test1/u0a57} (pid=2141, uid=10057) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 
at android.os.Parcel.readException(Parcel.java:1599) 
at android.os.Parcel.readException(Parcel.java:1552) 
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550) 
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778) 
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018) 
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468) 
at android.content.ContentResolver.query(ContentResolver.java:475) 
at android.content.ContentResolver.query(ContentResolver.java:434) 
at com.example.umairkhan.test1.MainActivity.fetchContacts(MainActivity.java:38) 
at com.example.umairkhan.test1.MainActivity.onCreate(MainActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+1

關鍵代碼似乎是:_Caused by:java.lang.SecurityException:Permission Denial:從ProcessRecord {b3e8b0d 2141:com.example.umairkhan.test1/u0a57}打開提供程序com.android.providers.contacts.ContactsProvider2( pid = 2141,uid = 10057)需要android.permission.READ_CONTACTS或android.permission.WRITE_CONTACTS_ – EJK

回答

0

由於錯誤提示

要求你必須在manifest文件添加權限android.permission.READ_CONTACTS或 android.permission.WRITE_CONTACTS

<uses-permission android:name="android.permission.READ_CONTACTS" /> 

<uses-permission android:name="android.permission.WRITE_CONTACTS" /> 

更多有關android-permissions訪問android developer

Permissions

希望這將有助於。

+0

沒有它沒有...........仍然有錯誤 –

+0

@umairkhan什麼是logcat後,你把這兩個權限。這次是相同的還是不同的錯誤?你能檢查一下嗎? – KDeogharkar

+0

不能把它放在評論因爲它太長 –