0

I am trying to fetch data using ParseQuery.But findInBackground() method is always returning NullPointerException. Here is the code snippet:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if ((ni != null) && (ni.isConnected())) {
            ParseQuery<Alert> query = Alert.getQuery();
            query.whereEqualTo("category", "Emergency");
            Log.d(TAG,"before calling query");
            query.findInBackground(new FindCallback<Alert>() {
                public void done(List<Alert> list, ParseException exp) 
                {
                    if(exp == null){
                        for(int i=0;i<list.size();i++)
                        {
                            Alert alert = list.get(i);
                            Log.d(TAG, "Title = "+ alert.getTitle() + " link = "+ alert.getLink());
                        }

                    } else {
                        Log.d(TAG,"no results !!"+ exp.getMessage()+" code ="+ exp.getCode());
                    }
                };

            });
        }

I have checked the permission also, In Table it is showing Public Read/Write ACL.

[EDIT]In my Application.java

ParseObject.registerSubclass(Alert.class);
Parse.initialize(this, "ABC", "XYZ");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);   

So can anyone suggest what am I missing?

5
  • can you plz share parse table Commented Nov 18, 2015 at 4:58
  • 1
    I think you have created Alert subclass of ParseObject but did not register it in Application .java, register it like ParseObject.registerSubclass(Alert.class); Commented Nov 18, 2015 at 5:17
  • @ParagChauhan you mean from the Data Browser ? Commented Nov 18, 2015 at 17:01
  • @ved I tried it even after this I am getting nullpointerexception, what else is missing ? Commented Nov 18, 2015 at 17:01
  • yes,make sure your table name,column name should be same Commented Nov 19, 2015 at 11:56

2 Answers 2

2

NullPointerException in a query only happens in 2 cases -

  • The class hasn't been registered with Parse.Solution is to add the following line after Parse.initialize -

    ParseObject.registerSubclass(Alert.class);

  • The class model has been changed either on parse website or in android code. Solution is to drop the table on parse dashboard.

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

1 Comment

Thanks for response ...even after adding it, still I am getting the same NullPointerException. And what do you mean by class model has been changed ? because I haven't modified anywhere.
0

Adding to Tushar's reply, the other thing which I was missing, the android:name field in tag in Manifest file.

<application
        android:name ="com.tutorial.Alert.SampleApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

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.