Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:45:18+00:00 2026-06-13T10:45:18+00:00

I have a problem with my app. I’m trying to execute a query, but

  • 0

I have a problem with my app.
I’m trying to execute a query, but the app stops every time.
This error occurs while trying to the execute query.
I’m learning from Android Pro 3 book, but code presented in this book is deprecated:

package com.example.contactsabuout;

import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.ContactsContract;
import android.app.Activity;
import android.database.Cursor;
import android.util.Log;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

    private static Context context;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MainActivity.context = getApplicationContext();

        Log.v("INFO", "Completed: onCreate.");
    }

    public static Context getAppContext() {
        return MainActivity.context;
    }

    public void doQuery(View view) {

         Uri peopleBaseUri = ContactsContract.Contacts.CONTENT_URI;
         Log.v("II","Button clicked.");
         Log.v("II", "Uri for ContactsContract.Contacts: " + peopleBaseUri);
         Context context = getAppContext();
         Log.v("II", "Got context: " + context);
         Cursor cur;
         Log.v("II", "Created cursor: cur");
         cur = context.getContentResolver().query(peopleBaseUri, null, null, null, null);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

FROM LogCat

10-28 17:45:02.513: V/INFO(4677): Completed: onCreate.
10-28 17:45:02.613: D/libEGL(4677): loaded /system/lib/egl/libGLES_android.so
10-28 17:45:02.653: D/libEGL(4677): loaded /system/lib/egl/libEGL_adreno200.so
10-28 17:45:02.723: D/libEGL(4677): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
10-28 17:45:02.723: D/libEGL(4677): loaded /system/lib/egl/libGLESv2_adreno200.so
10-28 17:45:03.014: I/Adreno200-EGLSUB(4677): <ConfigWindowMatch:2078>: Format RGBA_8888.
10-28 17:45:03.054: D/OpenGLRenderer(4677): Enabling debug mode 0
10-28 17:45:03.254: D/OpenGLRenderer(4677): has fontRender patch
10-28 17:45:03.274: D/OpenGLRenderer(4677): has fontRender patch
10-28 17:45:12.873: V/II(4677): Button clicked.
10-28 17:45:12.873: V/II(4677): Uri for ContactsContract.Contacts: content://com.android.contacts/contacts, rest will be null
10-28 17:45:12.873: V/II(4677): Got context: android.app.Application@40d83d90
10-28 17:45:12.873: V/II(4677): Created cursor: cur
10-28 17:45:12.933: D/AndroidRuntime(4677): Shutting down VM
10-28 17:45:12.933: W/dalvikvm(4677): threadid=1: thread exiting with uncaught exception (group=0x40aaf228)
10-28 17:45:12.953: E/AndroidRuntime(4677): FATAL EXCEPTION: main
10-28 17:45:12.953: E/AndroidRuntime(4677): java.lang.IllegalStateException: Could not execute method of the activity
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.view.View$1.onClick(View.java:3071)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.view.View.performClick(View.java:3538)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.view.View$PerformClick.run(View.java:14330)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.os.Handler.handleCallback(Handler.java:608)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.os.Looper.loop(Looper.java:156)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.app.ActivityThread.main(ActivityThread.java:4977)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at java.lang.reflect.Method.invokeNative(Native Method)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at java.lang.reflect.Method.invoke(Method.java:511)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at dalvik.system.NativeStart.main(Native Method)
10-28 17:45:12.953: E/AndroidRuntime(4677): Caused by: java.lang.reflect.InvocationTargetException
10-28 17:45:12.953: E/AndroidRuntime(4677):     at java.lang.reflect.Method.invokeNative(Native Method)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at java.lang.reflect.Method.invoke(Method.java:511)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.view.View$1.onClick(View.java:3066)
10-28 17:45:12.953: E/AndroidRuntime(4677):     ... 11 more
10-28 17:45:12.953: E/AndroidRuntime(4677): Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/contacts from pid=4677, uid=10155 requires android.permission.READ_CONTACTS
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.os.Parcel.readException(Parcel.java:1332)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:406)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at android.content.ContentResolver.query(ContentResolver.java:315)
10-28 17:45:12.953: E/AndroidRuntime(4677):     at com.example.contactsabuout.MainActivity.doQuery(MainActivity.java:47)
10-28 17:45:12.953: E/AndroidRuntime(4677):     ... 14 more

I’m trying to learn android.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:45:19+00:00Added an answer on June 13, 2026 at 10:45 am

    This line in the LogCat:

    Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/contacts from pid=4677, uid=10155 requires android.permission.READ_CONTACTS

    Informs you that you need to add:

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

    to your Manifest.


    Add it in the <manifest> element, the same as <application> or <uses-sdk>:

    <manifest>
    
        <uses-sdk />
        <uses-permission android:name="android.permission.READ_CONTACTS" />
        <application />
    
    </manifest>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple Spring AOP app, but I have problem with
I have a strange problem with in-app billing RESTORE_TRANSACTION command. Every request RESTORE_TRANSACTION request
I have a problem - my app works fine on the simulator, but on
i have problem with my android app, i searched but cannot find answer, i
I have problem in my heroku app, I am trying to send email using
I have a problem integrating my app with facebook. I am trying to read
I have a problem with my app, which run well on the simulator but
I have this problem of my app crashing (only when press a certain UIButton)
i have problem switching locale language while app is still running, how to do
I have this problem with an app of a printer. I need to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.