Starting map activity in Android 2.1 and 1.5 causes crash-Collection of common programming errors
In an appwidget I develop I have a problem that when I start a map activity in Android 2.1 and 1.5 it causes a crash. I only notriced this in 1.5 and 2.1, it may happen in 1.6 but I haven’t tested yet. The problem magically disappears if I let the app run for a while, say 30 minutes to an hour before touching it.
I am pretty convinced this is not a bug in my app, but an Android bug. Is there a way to work around it?
Stack trace:
I/ActivityManager( 576): Starting activity: Intent { flags=0x10000000 comp={net.example.example/net.example.example.ExampleTabWidget} } D/dalvikvm( 576): GC freed 8147 objects / 444432 bytes in 84ms W/dalvikvm( 822): Unable to resolve superclass of Lnet/example/example/ExampleMaps; (55) W/dalvikvm( 822): Link of class 'Lnet/example/example/ExampleMaps;' failed E/dalvikvm( 822): Could not find class 'net.example.example.ExampleMaps', referenced from method net.example.example.ExampleTabWidget.onCreate W/dalvikvm( 822): VFY: unable to resolve const-class 109 (Lnet/example/example/ExampleMaps;) in Lnet/example/example/ExampleTabWidget; W/dalvikvm( 822): VFY: rejecting opcode 0x1c at 0x011c W/dalvikvm( 822): VFY: rejected Lnet/example/example/ExampleTabWidget;.onCreate (Landroid/os/Bundle;)V W/dalvikvm( 822): Verifier rejected class Lnet/example/example/ExampleTabWidget; W/dalvikvm( 822): Class init failed in newInstance call (Lnet/example/example/ExampleTabWidget;) D/AndroidRuntime( 822): Shutting down VM W/dalvikvm( 822): threadid=3: thread exiting with uncaught exception (group=0x4000fe70) E/AndroidRuntime( 822): Uncaught handler: thread main exiting due to uncaught exception E/AndroidRuntime( 822): java.lang.VerifyError: net.example.example.ExampleTabWidget E/AndroidRuntime( 822): at java.lang.Class.newInstanceImpl(Native Method) E/AndroidRuntime( 822): at java.lang.Class.newInstance(Class.java:1472) E/AndroidRuntime( 822): at android.app.Instrumentation.newActivity(Instrumentation.java:1097) E/AndroidRuntime( 822): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186) E/AndroidRuntime( 822): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) E/AndroidRuntime( 822): at android.app.ActivityThread.access$1800(ActivityThread.java:112) E/AndroidRuntime( 822): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) E/AndroidRuntime( 822): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 822): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 822): at android.app.ActivityThread.main(ActivityThread.java:3948) E/AndroidRuntime( 822): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 822): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime( 822): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) E/AndroidRuntime( 822): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) E/AndroidRuntime( 822): at dalvik.system.NativeStart.main(Native Method) I/Process ( 576): Sending signal. PID: 822 SIG: 3 I/dalvikvm( 822): threadid=7: reacting to signal 3 I/dalvikvm( 822): Wrote stack trace to '/data/anr/traces.txt' I/Process ( 822): Sending signal. PID: 822 SIG: 9 I/ActivityManager( 576): Process net.example.example (pid 822) has died.
Relevant code, starting map activity from tab activity:
intent=new Intent().setClass(this, ExampleMaps.class);
intent.putExtra("t1",t1);
intent.putExtra("t2",t2);
intent.putExtra("m1",m1);
intent.putExtra("details",details);
spec=tabHost.newTabSpec("Examples").setIndicator("", res.getDrawable(R.drawable.example_tab_icons_map)).setContent(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
tabHost.addTab(spec);
(..)
tabHost.setCurrentTab(0);
The map activity:
public class ExampleMaps extends MapActivity
{
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
@Override
protected boolean isRouteDisplayed()
{
return false;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
double t1=0, t2=0;
String alerttext=ExampleWidgetProvider.NODATA, mag, details=ExampleWidgetProvider.NODATA;
int m1=1;
Drawable drawable;
Bundle extras=getIntent().getExtras();
if(extras !=null)
{
(..)
Afetr checking Android java.lang.VerifyError? and some other places I haven’t yet found a solution.
The following already were set properly:
project.properties
target=Google Inc.:Google APIs:3
Manifest, in “applications”:
(...)
Including these in map activity:
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;