0

I am trying to query all the parse.com users registered in my app. I followed the guide and wrote this query

try{
    name=Name.getText().toString();
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereMatches("username", name);
    query.findInBackground(new FindCallback<ParseUser>() {
    public void done(List<ParseUser> objects, ParseException e) {
            if (e == null) {
                if (!objects.isEmpty()) {
                    show.setText(String.valueOf(objects.size()));
                    for (ParseUser singleobject : objects) {
                    mail[i] = singleobject.get("email").toString();
                    uname[i] = singleobject.get("username").toString();
                    i++;
                    }
                } else {
                    show.setText("No Tuples");
                }
            } else {
               Toast.makeText(getApplicationContext(), "Query Not Successful", Toast.LENGTH_LONG).show();
            }
        }
    });
  }catch (NullPointerException x){
        Toast.makeText(getApplicationContext(), "Null Pointer Exception", Toast.LENGTH_LONG);
    }}

This query works well when the input retrieves a single tuple but when I give an input that retrieves multiple tuples it is throwing a NULL POINTER EXCEPTION like this

Process: com.example.nirmal.sportsparse, PID: 15097
java.lang.NullPointerException
        at com.example.nirmal.sportsparse.search_players$2.done(search_players.java:108)
        at com.example.nirmal.sportsparse.search_players$2.done(search_players.java:99)
        at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5292)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)

The error code says that there is a NULL pointer in findInBackground() and inside the for loop. I am sure that the input I gave must retrieve atleast 2 tuples as a result.

Sometimes it also throws this error and I have no idea what this means

libcore.io.ErrnoException: close failed: EBADF (Bad file number)
        at libcore.io.Posix.close(Native Method)
        at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
        at com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:220)
        at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
        at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
        at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:700)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
        at dalvik.system.NativeStart.main(Native Method)

The array are declared like this

String name,mail[]=new String[100],uname[]=new String[100];

Can anyone tell me where I am going wrong??

8
  • what about 'i' value where u declared ? Commented Dec 10, 2015 at 18:03
  • @RameshBhupathi The i is initialised before the try block. Looks like I didn't copy it while pasting the code. But it is there and initialised to 0. Commented Dec 11, 2015 at 11:46
  • check declaration of arrays ,its better to use Arraylists instead arrays Commented Dec 11, 2015 at 13:13
  • @RameshBhupathi I have posted the array declaration.Please check if there is anything wrong with it. I will try to implement Arraylists Commented Dec 11, 2015 at 13:18
  • if u have any problem with Arraylist usage just ask Commented Dec 11, 2015 at 13:32

1 Answer 1

1

In the callback "done" , the JSON API , Normally allow 2 steps...

Check element exists

Stringify element

Note that

uname[i] = singleobject.get("username").toString();

Trys doing it all at once and throws an exception on columns that may be "undefined" in the parse object returned.

Check exists first

Then stringify

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.