当我尝试在Pushwoosh库中更新pushwoosh应用程序时出现错误。我已在Gradle中更新了它。
07-06 18:21:59.637 19950-19950/com.ahmet.sen E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ahmet.sen, PID: 19950
java.lang.ExceptionInInitializerError
at com.ahmet.sen.MainActivity.onCreate(MainActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.pushwoosh.notification.j com.pushwoosh.c.d()' on a null object reference
at com.pushwoosh.Pushwoosh.<init>(Unknown Source)
at com.pushwoosh.Pushwoosh.<clinit>(Unknown Source)
at com.ahmet.sen.MainActivity.onCreate(MainActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我收到错误
Pushwoosh.getInstance().registerForPushNotifications();
答案 0 :(得分:0)
在此处复制Pushwoosh Github的回复:
这不是Pushwoosh SDK的错误。这是Android应用环境中多处理器应用程序的特性。
当您集成LeakCanary,AppMetrica等分析工具时,这些库会为自己启动一个新流程。在此过程中创建了一个新的应用程序实例。但是你不需要在这个单独的过程中监听推送,所以默认情况下你不应该在registerForPushNotifications()
内调用Application.onCreate()
。
因此有两种可能的解决方案:
不要在registerForPushNotifications
Application.onCreate()
如果要在Application.onCreate()中调用registerForPushNotifications,则应该检查应用程序的主进程:
List < ActivityManager.RunningAppProcessInfo > runningAppProcesses = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses();
if (runningAppProcesses != null && runningAppProcesses.size() != 0) {
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo: runningAppProcesses) {
boolean isCurrentProcess = runningAppProcessInfo.pid == android.os.Process.myPid();
boolean isMainProcessName = getPackageName().equals(runningAppProcessInfo.processName);
if (isCurrentProcess && isMainProcessName) {
Pushwoosh.getInstance().registerForPushNotifications(...);
break;
}
}
}