1

I have tried to solve this error, and even with research, my attempts have been unsuccessful. In particular, I am receiving the following error: Cannot instantiate the type List

Below is the code:

public class MatchingActivity extends Activity {


    protected ParseRelation<ParseUser> mFriendsRelation;
    protected ParseUser mCurrentUser;   
    protected List<ParseUser> mUsers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.matching);
        // Show the Up button in the action bar.
         //create list variable
         mUsers = new List<ParseUser>(); 



    }
    @Override
    protected void onResume() {
        super.onResume();

        mCurrentUser = ParseUser.getCurrentUser();


        setProgressBarIndeterminateVisibility(true);

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> users, ParseException e) {
                if (e == null) {

                    //add all the users to your list variable 
                    mUsers.addAll(users); 

                } else {
                    // Something went wrong.
                }
            }
        });

        //check the size of your list to see how big it is before accessing it
        final int size = mUsers.size(); 

       //or use a loop to loop through each one
        for(ParseUser mParseUser : mUsers)
        {
              //skip over the current user
           if(mParseUser == ParseUser.getCurrentUser())
               continue; 

           mParseUser.getString("name");
           mParseUser.getNumber("age"); 
           mParseUser.getString("headline");
        }

    }
    }   

Any help would be greatly appreciated. Thanks in advance

Update

public class MatchingActivity extends Activity {


    protected ParseRelation<ParseUser> mFriendsRelation;
    protected ParseUser mCurrentUser;   
    protected List<ParseUser> mUsers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.matching);
        // Show the Up button in the action bar.
         //create list variable
        mUsers = (List<ParseUser>) findViewById(R.id.listView1);



    }
    @Override
    protected void onResume() {
        super.onResume();

        mCurrentUser = ParseUser.getCurrentUser();


        setProgressBarIndeterminateVisibility(true);

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> users, ParseException e) {
                if (e == null) {



                  //add all the users to your list variable 
                    mUsers.addAll(users); 



                } else {
                    // Something went wrong.
                }
            }
        });

        //check the size of your list to see how big it is before accessing it
        final int size = mUsers.size(); 

       //or use a loop to loop through each one
        for(ParseUser mParseUser : mUsers)
        {
              //skip over the current user
           if(mParseUser == ParseUser.getCurrentUser())
               continue; 

           mParseUser.getString("name");
           mParseUser.getNumber("age"); 
           mParseUser.getString("headline");

           ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                   this, 
                   android.R.layout.simple_list_item_1, Unsure what to input here, 
                   as I want to return all three items (name, age, headline) from parse into the list);
           mUsers.setAdapter(arrayAdapter);
        }

    }
    }   

An error prompted The method setAdapter(ArrayAdapter) is undefined for the type List

Thanks for your support

user3827788
  • 311
  • 2
  • 9
  • 18

2 Answers2

3

You cannot instantiate Interface List with new List()

The keyword new is for creating (instantiating) object. In this case, you can instantiate Interface List with any class that implements List

mUsers = new ArrayList<ParseUser>(); //example with ArrayList

See All Known Implementing Classes: of List in Java api here.

Wundwin Born
  • 3,467
  • 19
  • 37
  • Thank you for your prompt response, and clarification. That has greatly helped resolved the error. If you don't mind me asking, how would I relate the arraylist in my layout so that the information populated through parse would be displayed in the actual application, since as of now it is blank. – user3827788 Aug 04 '14 at 05:22
  • @user3827788 This [link1](http://stackoverflow.com/questions/1917773/dynamic-listview-in-android-app?lq=1) and [link2](http://stackoverflow.com/questions/5070830/populating-a-listview-using-arraylist) will help you to use `ListView` – Wundwin Born Aug 04 '14 at 05:35
  • Thanks for your suggestion of ListView. I have looked at both links, and have tried to incorporate that into my code, but have encountered a few issues, and confusions. I have added my updated code under the update section of my initial post. It would helpful if you could take a look it, and kindly advise. – user3827788 Aug 04 '14 at 06:46
  • @user3827788 It would be better if you post as a new question to be elegant, as there are problems in your code of `findViewById()` and `setAdapter` method calls. – Wundwin Born Aug 04 '14 at 08:17
2

List is an interface. Interfaces cannot be instantiated.

So Try this:

mUsers = new ArrayList<ParseUser>();

Instead of

mUsers = new List<ParseUser>(); 

Reference: Cannot instantiate the type List<Product>

Community
  • 1
  • 1
Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
  • Thank you for your prompt response, and clarification. That has greatly helped resolved the error. If you don't mind me asking, how would I relate the arraylist in my layout so that the information populated through parse would be displayed in the actual application, since as of now it is blank. – user3827788 Aug 04 '14 at 05:19
  • You can use ListView in your layout page for displaying the result – Krupa Patel Aug 04 '14 at 05:31
  • Thanks for your suggestion of ListView. I have tried to incorporate that into my code, but have encountered a few issues, and confusions. I have added my updated code under the update section of my initial post. It would helpful if you could take a look it, and kindly advise. – user3827788 Aug 04 '14 at 06:45