Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10691] Android: Android app crashes when Annotation latitude/longitude is not set in createAnnotation()

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-09-13T14:56:05.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.0, Sprint 2012-19 API, 2012 Sprint 19
ComponentsAndroid
Labelsapi, module_map, parity, qe-review, qe-testadded
ReporterTony Lukasavage
AssigneeHieu Pham
Created2012-08-28T13:01:31.000+0000
Updated2012-12-21T00:34:19.000+0000

Description

Problem

On Android, you must set the latitude and longitude properties of a Ti.Map.Annotation in the createAnnotation() function, otherwise your app will crash with the error log below when Android attempts to add the annotation to a Ti.Map.View at runtime. iOS and Mobileweb can specify these properties at any time before the annotations are added and work fine.

Proposed Fix

Allow longitude and latitude to be set on an Annotation anytime before the annotations are assigned to a Ti.Map.View on Android.

Test Case

var win = Titanium.UI.createWindow();

// This will crash an android app. If you uncomment the latitude and longitude
// in the createAnnotation() call and comment the assignments after it, all 
// will work fine with no crash.
var ann = Ti.Map.createAnnotation({
    animate: true,
    pincolor: Ti.Map.ANNOTATION_RED,
    title: "Mountain View",
    // latitude: 37.389569,
    // longitude: -122.050212
});
ann.latitude = 37.389569;
ann.longitude = -122.050212;  

var map = Ti.Map.createView({
    region: {
        latitude: 37.38,
        latitudeDelta: .2,
        longitude: -122.05,
        longitudeDelta: .2
    },
    annotations: [ann]
});

win.add(map);
win.open();

android error log

E/TiApplication(22490): (main) [1,521] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appc.navgroup/com.appc.navgroup.NavgroupActivity}: java.lang.NullPointerException; Titanium 2.1.1,2012/07/27 14:01,0fd84a2
E/TiApplication(22490): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appc.navgroup/com.appc.navgroup.NavgroupActivity}: java.lang.NullPointerException
E/TiApplication(22490): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/TiApplication(22490): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/TiApplication(22490): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/TiApplication(22490): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/TiApplication(22490): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/TiApplication(22490): 	at android.os.Looper.loop(Looper.java:137)
E/TiApplication(22490): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
E/TiApplication(22490): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/TiApplication(22490): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/TiApplication(22490): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/TiApplication(22490): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/TiApplication(22490): 	at dalvik.system.NativeStart.main(Native Method)
E/TiApplication(22490): Caused by: java.lang.NullPointerException
E/TiApplication(22490): 	at com.google.android.maps.ItemizedOverlay.populate(ItemizedOverlay.java:311)
E/TiApplication(22490): 	at ti.modules.titanium.map.TiMapView$TitaniumOverlay.setAnnotations(TiMapView.java:186)
E/TiApplication(22490): 	at ti.modules.titanium.map.TiMapView.doSetAnnotations(TiMapView.java:783)
E/TiApplication(22490): 	at ti.modules.titanium.map.TiMapView.processProperties(TiMapView.java:657)
E/TiApplication(22490): 	at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:893)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:442)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:434)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:412)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:449)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:434)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:412)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:528)
E/TiApplication(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:205)
E/TiApplication(22490): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/TiApplication(22490): 	at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:365)
E/TiApplication(22490): 	at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:350)
E/TiApplication(22490): 	at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:235)
E/TiApplication(22490): 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:262)
E/TiApplication(22490): 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:187)
E/TiApplication(22490): 	at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:612)
E/TiApplication(22490): 	at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:437)
E/TiApplication(22490): 	at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:162)
E/TiApplication(22490): 	at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:99)
E/TiApplication(22490): 	at android.app.Activity.performCreate(Activity.java:4465)
E/TiApplication(22490): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/TiApplication(22490): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/TiApplication(22490): 	... 11 more
E/AndroidRuntime(22490): FATAL EXCEPTION: main
E/AndroidRuntime(22490): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appc.navgroup/com.appc.navgroup.NavgroupActivity}: java.lang.NullPointerException
E/AndroidRuntime(22490): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime(22490): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime(22490): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime(22490): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime(22490): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(22490): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(22490): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(22490): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(22490): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(22490): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(22490): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(22490): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(22490): Caused by: java.lang.NullPointerException
E/AndroidRuntime(22490): 	at com.google.android.maps.ItemizedOverlay.populate(ItemizedOverlay.java:311)
E/AndroidRuntime(22490): 	at ti.modules.titanium.map.TiMapView$TitaniumOverlay.setAnnotations(TiMapView.java:186)
E/AndroidRuntime(22490): 	at ti.modules.titanium.map.TiMapView.doSetAnnotations(TiMapView.java:783)
E/AndroidRuntime(22490): 	at ti.modules.titanium.map.TiMapView.processProperties(TiMapView.java:657)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:893)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:442)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:434)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:412)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:449)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:434)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:412)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:528)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:205)
E/AndroidRuntime(22490): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:365)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:350)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:235)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:262)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:187)
E/AndroidRuntime(22490): 	at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:612)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:437)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:162)
E/AndroidRuntime(22490): 	at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:99)
E/AndroidRuntime(22490): 	at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(22490): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(22490): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime(22490): 	... 11 more

Comments

  1. Tamila Smolich 2012-10-26

    Closing as fixed. Tested and verified on: Titanium Studio, build: 3.0.0.201210220122 Titanium SDK, build: 3.0.0.v20121025171611 Device: Galaxy Nexus (4.1.1)

JSON Source