Skip to content Skip to sidebar Skip to footer

Parsequery - Properly Handling Indexoutofboundsexception - Parse.com?

How does one properly handle throwIndexOutOfBoundsException? Basically, I'm querying for a user. If the user exists, it shows their profile. However, if no entry is found it crashe

Solution 1:

you can check if the list is empty :

@Overridepublicvoiddone(List<ParseUser> parseUsers, ParseException e) {
                                if (!parseUsers.isEmpty()) {
                                        // The query was successful.ParseUseruser= parseUsers.get(0);
                                        StringuserId= user.getObjectId();
                                        showProfileActivity(userId);

                                } else {
                                    // The query was unsuccessful.

                                }
                            }
                        });

or if you want to catch the Exception use try -catch like this :

@Overridepublicvoiddone(List<ParseUser> parseUsers, ParseException e) {
          if (e==null) {
            // The query was successful.try{
               ParseUseruser= parseUsers.get(0);
               StringuserId= user.getObjectId();
             }
       catch(ArrayIndexOutOfBoundsException e)
           {
       // Print message for user does not exist . 
            }
             showProfileActivity(userId);
            } 
              else {
                   // The query was unsuccessful.
                     }
                       }
                            });

Post a Comment for "Parsequery - Properly Handling Indexoutofboundsexception - Parse.com?"