我正在尝试通过此处的此链接实施 GA 广告系列测量 https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#campaign-params
所以,我已经完成了一切,但它NullpointerException
在我的代码中给出了。
// Get the intent that started this Activity.
Intent installIntent = this.getIntent();
Uri Installuri = installIntent.getData();
EasyTracker.getInstance().setContext(this);
if (installIntent != null) {
EasyTracker.getTracker().setCampaign(Installuri.getPath()); //line 82
}
那就是代码,它应该进行一般跟踪。没什么特别的。然而,在上面提到的第 82 行,它会抛出 NullPointerException。这是日志猫:
06-23 19:54:54.864: E/AndroidRuntime(13773): at android.os.Looper.loop(Looper.java:137)
06-23 19:54:54.864: E/AndroidRuntime(13773): at android.app.ActivityThread.main(ActivityThread.java:4441)
06-23 19:54:54.864: E/AndroidRuntime(13773): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 19:54:54.864: E/AndroidRuntime(13773): at java.lang.reflect.Method.invoke(Method.java:511)
06-23 19:54:54.864: E/AndroidRuntime(13773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-23 19:54:54.864: E/AndroidRuntime(13773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-23 19:54:54.864: E/AndroidRuntime(13773): at dalvik.system.NativeStart.main(Native Method)
06-23 19:54:54.864: E/AndroidRuntime(13773): Caused by: java.lang.NullPointerException
06-23 19:54:54.864: E/AndroidRuntime(13773): at uk.co.futurelite.elite.drum.machine.Main.onCreate(Main.java:82)
06-23 19:54:54.864: E/AndroidRuntime(13773): at android.app.Activity.performCreate(Activity.java:4465)
06-23 19:54:54.864: E/AndroidRuntime(13773): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-23 19:54:54.864: E/AndroidRuntime(13773): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
06-23 19:54:54.864: E/AndroidRuntime(13773): ... 11 more
IF
所以,如果不是这样,我会用语句检查它null
:
if (installIntent != null) {
那么,它抛出 NullPointerException 会发生什么?当它通过IF
声明时。
PS。我确实完成了它直到最后,虽然可能我必须将一些东西传递给广播接收器,但我可以在 logcat 中看到它成功接收到活动,如下所示:
06-23 19:54:56.544: W/GAV2(13773): Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
06-23 19:54:56.824: I/GAV2(13773): Thread[GAThread,5,main]: Campaign found: utm_source%3Dxdebugx%26utm_medium%3Dbutton
但是应用程序本身崩溃并且无法启动。