我正在尝试使用带有 Android SDK 的 ArcGIS 的示例 HelloWorld 应用程序。代码编译良好,但执行时出现灰屏。我已经看了一下这个问题,但它并没有解决我的问题。
这是我的源代码:
public class HelloWorld extends Activity {
MapView map = null;
ArcGISTiledMapServiceLayer tileLayer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
tileLayer = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer");
if(tileLayer.isInitialized() == true) //if a bad url is provided, this will fail
{ map.addLayer(tileLayer); }
else{
//if no layer is successfully added, the MapView will not initialize
Toast layerToast = Toast.makeText(this, "Layer didn't load, MapView won't initialize", Toast.LENGTH_LONG);
layerToast.show();
}
map.setOnStatusChangedListener(new OnStatusChangedListener() {
private static final long serialVersionUID = 1L;
public void onStatusChanged(Object source, STATUS status) {
//conditional checks if mapView's status has changed to initialized
if (OnStatusChangedListener.STATUS.INITIALIZED == status && source == map)
{
Toast mapViewToast = Toast.makeText(HelloWorld.this, "MapView loaded", Toast.LENGTH_LONG);
mapViewToast.show();
}
}
});
}
@Override
protected void onPause() {
super.onPause();
map.pause();
}
@Override protected void onResume() {
super.onResume();
map.unpause();
}
}
这是我的 LogCat:
06-18 10:51:21.413: E/ArcGIS(1544): url =http://services.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer
06-18 10:51:21.413: E/ArcGIS(1544): org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
06-18 10:51:21.413: E/ArcGIS(1544): at [Source: java.io.StringReader@4057ed68; line: 1, column: 2]
06-18 10:51:21.413: E/ArcGIS(1544): at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
06-18 10:51:21.413: E/ArcGIS(1544): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
06-18 10:51:21.413: E/ArcGIS(1544): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
06-18 10:51:21.413: E/ArcGIS(1544): at org.codehaus.jackson.impl.ReaderBasedParser._handleUnexpectedValue(ReaderBasedParser.java:1198)
06-18 10:51:21.413: E/ArcGIS(1544): at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:485)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.core.internal.b.a.e.a(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.core.internal.b.a.e.a(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.core.internal.b.a.e.a(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.core.internal.a.a.m.b(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.android.map.ags.ArcGISTiledMapServiceLayer.initLayer(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at com.esri.android.map.ags.ArcGISTiledMapServiceLayer$1.run(Unknown Source)
06-18 10:51:21.413: E/ArcGIS(1544): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
06-18 10:51:21.413: E/ArcGIS(1544): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-18 10:51:21.413: E/ArcGIS(1544): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-18 10:51:21.413: E/ArcGIS(1544): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-18 10:51:21.413: E/ArcGIS(1544): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-18 10:51:21.413: E/ArcGIS(1544): at java.lang.Thread.run(Thread.java:1019)