2

I am developping an Android application using tse ArcGIS SDK for Android. I am facing a problem when querying a featurelayer: the featurelayer I am using is hosted in our ArcGIS Online, and this is code I am using for the query: public final String mNonValidatedURL="http://LINK-TO-SERVICE/FeatureServer/0"; QueryParameters qParam = new QueryParameters(); qParam.setReturnGeometry(true); qParam.setOutSpatialReference(wm); qParam.setWhere("Validation='Non-validé'"); qParam.setReturnGeometry(true); qParam.setOutFields(new String[]{"*"}); Map<String, Order> obf = new HashMap<String, Order>(); obf.put("Date", Order.ASC); qParam.setOrderByFields(obf); QueryTask qTask = new QueryTask(mNonValidatedURL); try { FeatureResult results = qTask.execute(qParam); return results; } catch (Exception e) { Log.e("freaking exception", e.toString()); e.printStackTrace(); return null; }

sometimes the query is executed without problems but most of the time I am catching this error:

enter image description here

1 Answer 1

2

I've edited your code. Here is the worked code piece.

public class MainActivity extends AppCompatActivity {
    QueryTask qTask;
    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (Button)findViewById(R.id.button);


       qTask = new QueryTask("http://services3.arcgis.com/hjUMsSJ87zgoicvl/ArcGIS/rest/services/PINV/FeatureServer/0");

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AsyncQueryTask ayncQuery = new AsyncQueryTask();
                ayncQuery.execute("test");
            }
        });

    }


    private class AsyncQueryTask extends AsyncTask<String, Void, FeatureResult> {

        @Override
        protected void onPreExecute() {

        }

        @Override
        protected FeatureResult doInBackground(String... params) {


            QueryParameters qParameters = new QueryParameters();
            String whereClause = "Validation='Non-validé'";
            String outFields[] = {"*"};
            qParameters.setReturnGeometry(true);
            qParameters.setOutFields(outFields);
            qParameters.setWhere(whereClause);



            try {
                FeatureResult results = qTask.execute(qParameters);
                return results;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;

        }

        @Override
        protected void onPostExecute(FeatureResult results) {
            Envelope extent = new Envelope();

            if (results != null) {
                int size = (int) results.featureCount();
                for (Object element : results) {
                    if (element instanceof Feature) {
                        Feature feature = (Feature) element;
                        // turn feature into mGraphicQuery

                        if(feature.getGeometry().getType().equals(Geometry.Type.POLYGON)) {
                            SimpleFillSymbol sms = new SimpleFillSymbol(Color.GREEN, SimpleFillSymbol.STYLE.SOLID);
                            SimpleLineSymbol sms2 = new SimpleLineSymbol(Color.GREEN, 1f, SimpleLineSymbol.STYLE.SOLID);
                            sms.setOutline(sms2);
                            sms.setAlpha(100);

                            Graphic graphic = new Graphic(feature.getGeometry(),
                                    sms, feature.getAttributes());

                            Polygon p = (Polygon) graphic.getGeometry();
                            p.queryEnvelope(extent);
                            extent.merge(extent);


                        }

                        else if (feature.getGeometry().getType().equals(Geometry.Type.POINT)){

                            SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.RED,15,SimpleMarkerSymbol.STYLE.CIRCLE);

                            Graphic graphic = new Graphic(feature.getGeometry(),
                                    sms, feature.getAttributes());

                            Point p = (Point) graphic.getGeometry();
                            p.queryEnvelope(extent);
                            extent.merge(extent);
                        }







                    }
                }



            }
            if(results.featureCount()==0){
                Toast.makeText(MainActivity.this, "No result", Toast.LENGTH_SHORT).show();
            }



        }

    }


}
3
  • First thank you for your Answer, my code looks exactly like this, I am using AsyncTask the same way you mentionned, and it's working but sometimes it shows an "internal server error" as I mentionned in the question and I don't know why. I don't even understand what this error means so I can't look for a workaround..
    – Hamri Said
    Commented Jun 9, 2015 at 11:11
  • 1
    It causes by Esri's arcgis services maybe. You can debug your app or monitoring this error using Exception.
    – salihy
    Commented Jun 9, 2015 at 11:31
  • unfortunately debugging the application using LogCat doesnt show any further information about the error, like I posted in the picture in the question
    – Hamri Said
    Commented Jun 9, 2015 at 12:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.