-3

I cannot make any solution work... The result is always an app crash. I successfully made a listView, added items and got the selected ones, but I miss making the elements of the list the contacts' names instead of random ones.

Once selected, I will ask the number and PutExtra them in another activity.

EDIT: As suggested, here's the code I'm trying to get working:

            Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
        while (phones.moveToNext())
        {
            String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        }
        phones.close();

I'll insert this into a for loop for every contact, adding every time the strings name and phoneNumber to an ArrayList. However, when I press the button that should run this code (and the button is working fine), I get a long list of errors from the Android Monitor (here's the first lines):

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)

I've added the permission to the manifest:

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

Could you please help me? Thanks!

P.s. I've tryed multiple solutions from this previus topic, none of them work for me...

Community
  • 1
  • 1
Sixaxix9
  • 1
  • 3
  • 2
    SO is not a code-writing service. If you'd like to include your attempts at writing code in your question, along with the errors you are getting, I'm sure someone here would be happy to help. – azurefrog Sep 22 '16 at 22:13
  • 3
    In the meantime, please take the [Tour](http://stackoverflow.com/tour) and read the documentation in the [Help Center](http://stackoverflow.com/help). In particular, you should read about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and what sorts of questions are [on topic](http://stackoverflow.com/help/on-topic) here at SO. You might also find the [StackOverflow question checklist](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) quite useful. – azurefrog Sep 22 '16 at 22:13
  • Rather than explain that you have searched for solutions and ask directly for code, you must provide your errors and the code that you have. I have edited your post, but "nothing works, my app crashes" is not a question. – OneCricketeer Sep 22 '16 at 22:19
  • Thank you for editing and making things clear, this was my first post so please give me some time to get used to SO's workings. I'll update my post adding code and errors. Thanks! – Sixaxix9 Sep 22 '16 at 22:26

1 Answers1

0

Solved


It was all an app permission's issue. With android 6.0 Marshmallow you have to ask for the permissions directly in the Java code (during the onCreate method); later I'll post some sample code.


Big thanks to my friend Blitzuda that helped to bug out of my problem!

Sixaxix9
  • 1
  • 3