FeatureLayer from FeatureCollection

908
7
Jump to solution
10-22-2012 10:35 AM
EnriqueIbarra
New Contributor III
I'm a little desperate traying to load a featurecollection, I've launched the sample on my device (Samsung Galaxy Tab 7.0 - Android 4.0 IceCream Sandwich) and apparently it works, but it don't show graphics, just can see the Base Map.


In other idea order, i would like to work offline, don't know if I can save the featurecollection in the device and then work offline.
0 Kudos
1 Solution

Accepted Solutions
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
The LogCat states that there is an Unrecognized Character Escape.  It's an apostrophe.  What I did as a temporary solution is replace any apostrophe's with blanks.  So:
JsonParser parser = f.createJsonParser(jsonString.replace("'",""));

This seemed to work.  I'm not sure if there are any other character sequences that'll need to be escaped.  Since the feed is dynamic, there may be.  I'm not 100% sure.

In your LogCat, there is another error:
10-22 17:10:57.764: E/ArcGIS(19593): Caused by: java.io.FileNotFoundException: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/images/flickr.png

the URL to that image, which is the graphic defined in your feature layer definition and is placed on the map for all of the feed locations, no longer exists.  I replaced it with another flickr image I found on the web: 
http://www.byei.org/ecp/images/flickerIcon.jpg


As for working offline, you could store the JSON String to your SDCard or phone's internal storage and read it from there.

View solution in original post

0 Kudos
7 Replies
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
I'm a little desperate traying to load a featurecollection, I've launched the sample on my device (Samsung Galaxy Tab 7.0 - Android 4.0 IceCream Sandwich) and apparently it works, but it don't show graphics, just can see the Base Map.


In other idea order, i would like to work offline, don't know if I can save the featurecollection in the device and then work offline.


Check the LogCat.  I am getting an Unrecognized character escape ''' exception being thrown.  You might have to pick thru the RSS feed from Flickr as it may have changed.
0 Kudos
EnriqueIbarra
New Contributor III
Check the LogCat.  I am getting an Unrecognized character escape ''' exception being thrown.  You might have to pick thru the RSS feed from Flickr as it may have changed.


that's what I got on LogCat:
10-22 17:10:52.335: D/dalvikvm(19593): GC_CONCURRENT freed 225K, 5% free 7005K/7367K, paused 2ms+6ms
10-22 17:10:52.764: D/dalvikvm(19593): GC_FOR_ALLOC freed 292K, 8% free 7060K/7623K, paused 19ms
10-22 17:10:54.210: D/Test(19593): fiedName is title
10-22 17:10:54.210: D/Test(19593): fiedName is link
10-22 17:10:54.217: D/Test(19593): fiedName is description
10-22 17:10:54.217: D/Test(19593): fiedName is modified
10-22 17:10:54.217: D/Test(19593): fiedName is generator
10-22 17:10:54.217: D/Test(19593): fiedName is items
10-22 17:10:54.257: W/System.err(19593): org.codehaus.jackson.JsonParseException: Unrecognized character escape ''' (code 39)
10-22 17:10:54.257: W/System.err(19593):  at [Source: java.io.StringReader@412bf070; line: 87, column: 23]
10-22 17:10:54.257: W/System.err(19593):  at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
10-22 17:10:54.264: W/System.err(19593):  at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
10-22 17:10:54.264: W/System.err(19593):  at org.codehaus.jackson.impl.JsonParserMinimalBase._handleUnrecognizedCharacterEscape(JsonParserMinimalBase.java:496)
10-22 17:10:54.264: W/System.err(19593):  at org.codehaus.jackson.impl.ReaderBasedParser._decodeEscaped(ReaderBasedParser.java:1606)
10-22 17:10:54.264: W/System.err(19593):  at org.codehaus.jackson.impl.ReaderBasedParser._skipString(ReaderBasedParser.java:1406)
10-22 17:10:54.264: W/System.err(19593):  at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:366)
10-22 17:10:54.272: W/System.err(19593):  at com.esri.arcgis.android.samples.featurecollection.FeatureCollection.generateGraphics(FeatureCollection.java:181)
10-22 17:10:54.272: W/System.err(19593):  at com.esri.arcgis.android.samples.featurecollection.FeatureCollection.access$1(FeatureCollection.java:163)
10-22 17:10:54.272: W/System.err(19593):  at com.esri.arcgis.android.samples.featurecollection.FeatureCollection$1.onStatusChanged(FeatureCollection.java:95)
10-22 17:10:54.272: W/System.err(19593):  at com.esri.android.map.c.b(Unknown Source)
10-22 17:10:54.272: W/System.err(19593):  at com.esri.android.map.c.handleMessage(Unknown Source)
10-22 17:10:54.272: W/System.err(19593):  at android.os.Handler.dispatchMessage(Handler.java:95)
10-22 17:10:54.280: W/System.err(19593):  at android.os.Looper.loop(Looper.java:137)
10-22 17:10:54.280: W/System.err(19593):  at android.app.ActivityThread.main(ActivityThread.java:4514)
10-22 17:10:54.280: W/System.err(19593):  at java.lang.reflect.Method.invokeNative(Native Method)
10-22 17:10:54.280: W/System.err(19593):  at java.lang.reflect.Method.invoke(Method.java:511)
10-22 17:10:54.280: W/System.err(19593):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-22 17:10:54.280: W/System.err(19593):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-22 17:10:54.288: W/System.err(19593):  at dalvik.system.NativeStart.main(Native Method)
10-22 17:10:57.733: D/dalvikvm(19593): GC_CONCURRENT freed 428K, 9% free 7070K/7687K, paused 2ms+2ms
10-22 17:10:57.764: E/ArcGIS(19593): Failed to initialize the ArcGISFeatureLayer.
10-22 17:10:57.764: E/ArcGIS(19593): java.lang.reflect.InvocationTargetException
10-22 17:10:57.764: E/ArcGIS(19593):  at java.lang.reflect.Constructor.constructNative(Native Method)
10-22 17:10:57.764: E/ArcGIS(19593):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.internal.util.b.e(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.internal.c.a.a(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.internal.c.f.a(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.internal.c.f.a(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.android.map.ags.ArcGISFeatureLayer.<init>(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.android.map.ags.ArcGISFeatureLayer.<init>(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.arcgis.android.samples.featurecollection.FeatureCollection$1.onStatusChanged(FeatureCollection.java:104)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.android.map.c.b(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.android.map.c.handleMessage(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at android.os.Handler.dispatchMessage(Handler.java:95)
10-22 17:10:57.764: E/ArcGIS(19593):  at android.os.Looper.loop(Looper.java:137)
10-22 17:10:57.764: E/ArcGIS(19593):  at android.app.ActivityThread.main(ActivityThread.java:4514)
10-22 17:10:57.764: E/ArcGIS(19593):  at java.lang.reflect.Method.invokeNative(Native Method)
10-22 17:10:57.764: E/ArcGIS(19593):  at java.lang.reflect.Method.invoke(Method.java:511)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-22 17:10:57.764: E/ArcGIS(19593):  at dalvik.system.NativeStart.main(Native Method)
10-22 17:10:57.764: E/ArcGIS(19593): Caused by: java.io.FileNotFoundException: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/images/flickr.png
10-22 17:10:57.764: E/ArcGIS(19593):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
10-22 17:10:57.764: E/ArcGIS(19593):  at java.net.URL.openStream(URL.java:462)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.symbol.PictureMarkerSymbol.a(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.symbol.PictureMarkerSymbol.<init>(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.android.a.a.a(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  at com.esri.core.renderer.SimpleRenderer.<init>(Unknown Source)
10-22 17:10:57.764: E/ArcGIS(19593):  ... 19 more



I got the Unrecognized character escape ''' too, but don't know now what to do...
it suppose tht this is the url:
URI uri = URIUtils.createURI("http","api.flickr.com", -1
     , "/services/feeds/geo",
     URLEncodedUtils.format(nameValuePairs, "UTF-8"), null);
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
The LogCat states that there is an Unrecognized Character Escape.  It's an apostrophe.  What I did as a temporary solution is replace any apostrophe's with blanks.  So:
JsonParser parser = f.createJsonParser(jsonString.replace("'",""));

This seemed to work.  I'm not sure if there are any other character sequences that'll need to be escaped.  Since the feed is dynamic, there may be.  I'm not 100% sure.

In your LogCat, there is another error:
10-22 17:10:57.764: E/ArcGIS(19593): Caused by: java.io.FileNotFoundException: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/images/flickr.png

the URL to that image, which is the graphic defined in your feature layer definition and is placed on the map for all of the feed locations, no longer exists.  I replaced it with another flickr image I found on the web: 
http://www.byei.org/ecp/images/flickerIcon.jpg


As for working offline, you could store the JSON String to your SDCard or phone's internal storage and read it from there.
0 Kudos
EnriqueIbarra
New Contributor III
Thanks andrewb!
it works like a charm!!! realy very thanks! I think should learn to read often the LogCat.
I'll try to do it now offline.
and just another question, to apply a query is so easy like implement the query sample? and it's possible do an identify?
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
You can apply a query to your FeatureLayer.  Check out ArcGISFeatureLayer.queryFeatures(); in the API help.

Here's a sample.  Obviously you'll have to modify the where clause:

try {
      fLayer = new ArcGISFeatureLayer(layerDefinition, fs,
        options);
      Query q = new Query();
      q.setWhere("MYVAL = 'xyz'");
      q.setReturnGeometry(true);
      q.setOutFields(fLayer.getOutFields());   
      fLayer.queryFeatures(q, null);
      map.addLayer(fLayer);
      Toast.makeText(FeatureCollection.this, "Flicker feed contents added to feature layer", Toast.LENGTH_SHORT).show();
     } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
0 Kudos
EnriqueIbarra
New Contributor III

As for working offline, you could store the JSON String to your SDCard or phone's internal storage and read it from there.


Sorry for the nuisance Andrew, to read it from SD or internal storage should I store the result of the call to the getJsonResponse function and then just read that from the file stored? or should I only save the result of REST to my layer?


You can apply a query to your FeatureLayer.  Check out ArcGISFeatureLayer.queryFeatures(); in the API help.

Here's a sample.  Obviously you'll have to modify the where clause:

try {
      fLayer = new ArcGISFeatureLayer(layerDefinition, fs,
        options);
      Query q = new Query();
      q.setWhere("MYVAL = 'xyz'");
      q.setReturnGeometry(true);
      q.setOutFields(fLayer.getOutFields());   
      fLayer.queryFeatures(q, null);
      map.addLayer(fLayer);
      Toast.makeText(FeatureCollection.this, "Flicker feed contents added to feature layer", Toast.LENGTH_SHORT).show();
     } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }


Thanks for the advice, it's really helping
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
It's up to you, but i might store the JSON string.  then you can manipulate it as necessary
0 Kudos