cocos2d-x 3.17 crash

Hi everyone!
After update to cocos 3.17, We are seeing tons of “java.lang.NullPointerException” crash in Play Console. It happens in this line: mFrameLayout.addView(relativeLayout);

This is the code that contains that line:
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
RelativeLayout relativeLayout=new RelativeLayout(this);
mFrameLayout.addView(relativeLayout);
RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
AdView.LayoutParams.WRAP_CONTENT,
AdView.LayoutParams.WRAP_CONTENT);
adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeLayout.addView(adView, adViewParams);

I didn’t see this error when debugging on test device and can’t fix it. I use cocos2d-x 3.17 with android studio, google mobile ads sdk and google consent sdk. Please help me if you know about this bug.

Thanks!

What’s the complete error message or line? Without it, we aren’t able to help.

2 Likes

this is full report from developer console:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2262)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2316)
at android.app.ActivityThread.access$700 (ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1296)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:176)
at android.app.ActivityThread.main (ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative (Native Method)
at java.lang.reflect.Method.invoke (Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:869)
at dalvik.system.NativeStart.main (Native Method)
Caused by: java.lang.NullPointerException:
at org.cocos2dx.cpp.AppActivity.onCreate (AppActivity.java:178)
at android.app.Activity.performCreate (Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2225)

Line 178 in AppActivity.java is mFrameLayout.addView(relativeLayout);

Prerequisites: mFramelayout in created in this line. It’s called from onCreate. Your code has to be at the earliest here.

If you can’t see this while debugging, maybe it’s not a normal started activity, maybe “restored” one. Activate on your device in the developer option: “don’t save activities” (the text may differs). Then start your game, play it, press home, wait 10 sec, open your game over the recent list (and in the second test with the app icon).

I have no other idea, why this should happen.

Oh, i will try again with option: “don’t save activities”. Thank you!

1 Like