Select to view content in your preferred language

Fatal exceptions when updating from Beta to Release

2465
19
12-30-2011 09:18 AM
JasonKiesel
Deactivated User
We just updated the ESRI Android SDK to the latest version (going from beta to release) and we were at once riddled with new errors. The project didn't even build once when the .JAR files were updated. We had something on the order of 50 to 60 build errors. We've finally got the build errors gone, but now we can't even view an Activity that has a MapView included.

We've looked at the docs, even double checked them, but we're getting a fatal exception with the new SDK.
0 Kudos
19 Replies
WillCrick
Deactivated User
Can you provide some information on the fatal errors you are experiencing? e.g. When does it crash, the logcat logs, some information/code snippets on how you are loading and adding layers to your map etc...
0 Kudos
DanO_Neill
Deactivated User
The ArcGIS Runtime SDK for Android v1.0.1 uses OpenGL ES 2.0 API to render map images. This resulted in changes to the API from our beta release and are the most likely case for project errors in apps built with the beta API. You have a few options and all include refactoring your code to the release API. I believe the easiest approach is to create a New Project with all the same project name/package/etc. from your beta apps. This will ensure your project is updated to support the release API. Next import the source from your beta project into the New Project. You should get errors on your source code. These errors are most likely due one or all of the following:

1. API changes in your code. There have been some changes to the core API which will need to be refactored.
2. Map Layers are no longer Android Views. We no longer support adding layers through XML layout. You will need to add layers programmatically in Java. The base Layer class is used for all layers that can be added to a MapView. E.g. If you want to add an Dynamic Map Service layer you will need to use the ArcGISDynamicMapServiceLayer class.
3. MapView XML Layout. We no longer support adding MapView layer service URL's through XML layout. MapView is still an Android View but the underlying layers are not so you can still reference your MapView from XML layout but we only support Web Map URL's. You can still set the initial extent of your MapView in XML Layout.

As Will noted above, if you provide us with specific details about the errors you are experiencing we can help you resolve them. I understand this effort may be taxing, but we believe the benefits significantly outweigh the costs. I appreciate your attempt to find resolution within our doc system and we will work on providing some better documentation to support moving from our beta API to release.
0 Kudos
DennisBaliton
Emerging Contributor
This is in regards to Jason's original post.  I followed the instructions on importing an existing project and I have updated our source code so that it compiles using the new ESRI SDK.  The error occurs while loading and adding a mapview layer.

.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~  Stack Trace .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
01-03 11:05:13.521: E/AndroidRuntime(1660): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.citysourced/com.citysourced.activity.MapScreen}: java.lang.NullPointerException
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:1656)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at com.citysourced.activity.TabActivityGroup.startChildActivity(TabActivityGroup.java:16)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at com.citysourced.activity.MapActivityGroup.onCreate(MapActivityGroup.java:23)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
01-03 11:05:13.521: E/AndroidRuntime(1660):  ... 18 more
01-03 11:05:13.521: E/AndroidRuntime(1660): Caused by: java.lang.NullPointerException
01-03 11:05:13.521: E/AndroidRuntime(1660):  at com.citysourced.activity.MapScreen.onCreate(MapScreen.java:181)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
01-03 11:05:13.521: E/AndroidRuntime(1660):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)



.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~  Source Code .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
//Strings.xml
<string name="url_map_tiles">http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer</string>


//MapScreen.java
    mMapView.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url_map_tiles)));
//Retrieve the non-configuration instance data that was previously returned.
Object init = getLastNonConfigurationInstance();
  if (init != null) {
   mMapView.restoreState((String) init);
  }

               ...
0 Kudos
ArchanaAgarwal
Occasional Contributor
Hello Dennis,

Here is the code from the onCreate() method in the helloworld sample from the sdk.
Its been modified to get the url from values->string.xml.

Thanks
Archana

-----------------------------------------------------------------------------

public void onCreate(Bundle savedInstanceState) {
 
                // could not see these two lines in the code posted 
                super.onCreate(savedInstanceState);
  setContentView(R.layout.main);


 
  // Retrieve the map and initial extent from XML layout
  map = (MapView)findViewById(R.id.map);
  // Add dynamic layer to MapView
  //map.addLayer(new ArcGISDynamicMapServiceLayer("" +    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
 


                map.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url_map_tiles)));


 
  //Retrieve the non-configuration instance data that was previously returned.
  Object init = getLastNonConfigurationInstance();
  if (init != null) {
   map.restoreState((String) init);
  }
}
0 Kudos
DennisBaliton
Emerging Contributor
mMapView is an instance of the object MapView in our app, as map is in the HelloWorld example. Please explain if I'm missing something here.


mMapView.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url_map_tiles)));

        map.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url_map_tiles)));
0 Kudos
ArchanaAgarwal
Occasional Contributor
That is correct, and there are two ways you can create an instance, either by using the new operator
MapView m = new MapView(this)

Or in xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   
    <!-- MapView layout and initial extent -->
    <com.esri.android.map.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    initExtent = "-19332033.11, -3516.27, -1720941.80, 11737211.28">
   </com.esri.android.map.MapView>
  
</LinearLayout>

In code you would have to use the following :
map = (MapView)findViewById(R.id.map);

Here is the code to create mapview by using the new operator:
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  map = new MapView(this);
  map.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url)));
  setContentView(map);

  //Retrieve the non-configuration instance data that was previously returned.
  Object init = getLastNonConfigurationInstance();
  if (init != null) {
   map.restoreState((String) init);
  }
}


protected void onPause() {
  super.onPause();
  map.pause();
}
0 Kudos
DennisBaliton
Emerging Contributor
We're instantiating via XML- attaching code snippets from Java class file and XML(layout).


.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~   
.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~   
    // Instantiate MapView...
    mMapView = (MapView) findViewById(R.id.mapView);
// Add dynamic layer to MapView
    mMapView.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url_map_tiles)));
//Retrieve the non-configuration instance data that was previously returned.
Object init = getLastNonConfigurationInstance();
  if (init != null) {
   mMapView.restoreState((String) init);
  }


.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~   
.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~   
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent" >

    <RelativeLayout
        android:id="@+id/mapViewContent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/controlbuttons"
        android:layout_alignParentTop="true" >

  <!-- MapView layout and initial extent -->
  <com.esri.android.map.MapView
   android:id="@+id/map"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   initExtent = "-1.3296373526814876E7 3930962.41823043 -1.2807176545789773E7 4201243.7502468005">
  </com.esri.android.map.MapView>

    ...
0 Kudos
ArchanaAgarwal
Occasional Contributor
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mMapView = (MapView)findViewById(R.id.map);
mMapView.addLayer(new ArcGISDynamicMapServiceLayer(getString(R.string.url)));

//Retrieve the non-configuration instance data that was previously returned.
Object init = getLastNonConfigurationInstance();
if (init != null) {
mMapView.restoreState((String) init);
}
}

The code works with the additional lines as shown in red.
0 Kudos
DennisBaliton
Emerging Contributor
This is what we have.

  public void onCreate(Bundle savedInstanceState) {
    Utility.logInfo(CLASSNAME, "onCreate", "");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mycityhomescreen);
0 Kudos