I'm using EasyTracker google analytics library and my app have multiple activities. I want to track as event device model and system version info each time on app launch.
This code in onCreate method of my launcher activity
EasyTracker.getTracker().trackEvent("Others", "App launch", "The os version", 0);
crashes with
06-15 21:24:30.898: WARN/dalvikvm(1203): threadid=8: thread exiting with uncaught exception (group=0x4001d800)
06-15 21:24:30.898: ERROR/AndroidRuntime(1203): FATAL EXCEPTION: TrackerThread
java.lang.NullPointerException
at com.google.android.apps.analytics.GoogleAnalyticsTracker.createEvent(Unknown Source)
at com.google.android.apps.analytics.GoogleAnalyticsTracker.trackEvent(Unknown Source)
at com.google.android.apps.analytics.easytracking.GoogleAnalyticsTrackerDelegateImpl.trackEvent(Unknown Source)
at com.google.android.apps.analytics.easytracking.EasyTracker$11.run(Unknown Source)
at com.google.android.apps.analytics.easytracking.EasyTracker$TrackerThread.run(Unknown Source)
06-15 21:24:30.918: WARN/ActivityManager(58): Force finishing activity com.mycompany.myapp/com.mycompany.activity.HomeActivity
What I'm doing wrong?
You get a NullPointerException because the tracker is initialized in the onStart method of the base class TrackedActivity, which happens after onCreate. However, TrackedActivity automatically tracks the creation of the activity (trackPageView) so normally you do not need trackEvent here. You can successfully call trackEvent on any other method between onStart and onStop on the activity's lifecycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With