learner
learner

Reputation: 43

java.lang.RuntimeException: This query has an outstanding network connection. You have to wait until it's done

I am trying to populate the list view with the address by running query on the nearby locations from point g to the list of address/geopoint in the parse server.:

public class Map_Masti extends FragmentActivity {
    ParseGeoPoint g;
    private SupportMapFragment mapFragment;
    private TextView textView;
    private  ParseQueryAdapter<Rahees> adapter;
    private ParseQueryAdapter<Rahees> postsQueryAdapter;//this is outside oncreate
  private List <ParseGeoPoint> points=new ArrayList<ParseGeoPoint>();



    private void getG() {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.getInBackground("ccm3xKMmr4", new GetCallback<ParseUser>() {
            public void done(ParseUser object, ParseException e) {
                if (e == null) {
                    g = (ParseGeoPoint) object.get("user_Location");

                    display();


                } else {


                }
            }
        });
    }



    public void display()
    {


        // Set up a customized query
        ParseQueryAdapter.QueryFactory<Rahees> factory =
                new ParseQueryAdapter.QueryFactory<Rahees>() {
                    public ParseQuery<Rahees> create() {                    
                        ParseQuery<Rahees> query = Rahees.getQuery();

                        query.include("user");
                        query.whereWithinKilometers("Locations", g, 1000);

                        query.findInBackground(new FindCallback<Rahees>() {//here is the error
                            @Override
                            public void done(List<Rahees> objects, ParseException e) {
                                //to check if there is a result


                                } 
                            }
                        });
                        return query;
                    }
                };




        // Set up the query adapter
        postsQueryAdapter = new ParseQueryAdapter<Rahees>(this, factory) {
            @Override
            public View getItemView(Rahees post, View view, ViewGroup parent) {
                if (view == null) {

                    view = View.inflate(getContext(), R.layout.row1_of_listvew, null);
                }
                TextView contentView = (TextView) view.findViewById(R.id.textView1);
                TextView usernameView = (TextView) view.findViewById(R.id.textView2);
                contentView.setText(post.getInt("Address"));
                usernameView.setText(post.getInt("Address"));
                return view;
            }
        };




        postsQueryAdapter.setAutoload(false);

// ***************************Disable pagination, we'll manage the query limit ourselves********************************/


        postsQueryAdapter.setPaginationEnabled(false);


        //********************************** Attach the query adapter to the view/

        ListView postsListView = (ListView) findViewById(R.id.listview);

        postsListView.setAdapter(postsQueryAdapter);

        postsQueryAdapter.loadObjects();

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_masti);
        textView = (TextView) findViewById(R.id.text);
        mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
      getG();
    }
}
 //****************************************************************************//

Below is the error that I'm getting

01-17 12:35:11.434: E/AndroidRuntime(21497): FATAL EXCEPTION: main
01-17 12:35:11.434: E/AndroidRuntime(21497): Process: in.easyway2.com.learn_parse, PID: 21497
01-17 12:35:11.434: E/AndroidRuntime(21497): java.lang.RuntimeException: This query has an outstanding network connection. You have to wait until it's done.
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQuery.checkIfRunning(ParseQuery.java:948)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:1129)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQuery.findAsync(ParseQuery.java:1193)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQuery.findInBackground(ParseQuery.java:1180)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQueryAdapter.loadObjects(ParseQueryAdapter.java:387)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.parse.ParseQueryAdapter.loadObjects(ParseQueryAdapter.java:362)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at in.easyway2.com.learn_parse.Map_Masti.display(Map_Masti.java:177)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at in.easyway2.com.learn_parse.Map_Masti$1.done(Map_Masti.java:50)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at in.easyway2.com.learn_parse.Map_Masti$1.done(Map_Masti.java:45)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at android.os.Handler.handleCallback(Handler.java:733)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at android.os.Looper.loop(Looper.java:136)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at android.app.ActivityThread.main(ActivityThread.java:5001)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at java.lang.reflect.Method.invoke(Method.java:515)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-17 12:35:11.434: E/AndroidRuntime(21497):    at dalvik.system.NativeStart.main(Native Method)

New to Parse so not very sure , have just followed the instructions from the guide.

Upvotes: 0

Views: 179

Answers (2)

learner
learner

Reputation: 43

I should not have added execution of the query in factory query, the below part: query.findInBackground(new FindCallback() {//here is the error @Override public void done(List objects, ParseException e) { //to check if there is a result } } });

Upvotes: 0

user4909407
user4909407

Reputation:

You should try uninstalling and reinstalling the app again. This solved the problem for me at least.

Another thing you can try is to delete and recreate the object or class you are querying about.

Tell me if this worked.

Upvotes: 0

Related Questions