Error by building android with BaseGame

work on PC well, but show this error on my phone



Class mygame.Main init failed

E/AndroidHarness( 8807): java.lang.NullPointerException

E/AndroidHarness( 8807): at android.view.ViewGroup.addViewInner(ViewGroup.java:3010)

E/AndroidHarness( 8807): at android.view.ViewGroup.addView(ViewGroup.java:2900)

E/AndroidHarness( 8807): at android.view.ViewGroup.addView(ViewGroup.java:2880)

E/AndroidHarness( 8807): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:242)

E/AndroidHarness( 8807): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:232)

E/AndroidHarness( 8807): at android.app.Activity.setContentView(Activity.java:1806)

E/AndroidHarness( 8807): at com.jme3.app.AndroidHarness.layoutDisplay(AndroidHarness.java:419)

E/AndroidHarness( 8807): at com.jme3.app.AndroidHarness.onCreate(AndroidHarness.java:220)

E/AndroidHarness( 8807): at android.app.Activity.performCreate(Activity.java:4397)

E/AndroidHarness( 8807): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)

E/AndroidHarness( 8807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)

E/AndroidHarness( 8807): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)

E/AndroidHarness( 8807): at android.app.ActivityThread.access$500(ActivityThread.java:122)

E/AndroidHarness( 8807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)

E/AndroidHarness( 8807): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidHarness( 8807): at android.os.Looper.loop(Looper.java:132)

E/AndroidHarness( 8807): at android.app.ActivityThread.main(ActivityThread.java:4123)

E/AndroidHarness( 8807): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidHarness( 8807): at java.lang.reflect.Method.invoke(Method.java:491)

E/AndroidHarness( 8807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)

E/AndroidHarness( 8807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)

E/AndroidHarness( 8807): at dalvik.system.NativeStart.main(Native Method)

D/com.mobihand.cds.provider.CDSProviderImpl( 4540): isMsgInValidPlatform: paltform: ‘null’

I/AndroidHarness( 8807): onStart

I/AndroidHarness( 8807): onResume

D/com.mobihand.cds.provider.CDSProviderImpl( 4540): isMsgInValidPlatform: retValue: ‘true’

I/AndroidHarness( 8807): onPause

I/AndroidHarness( 8807): onStop

I/AndroidHarness( 8807): onRetainNonConfigurationInstance called

I/AndroidHarness( 8807): INFO AndroidHarness 涓婂崍1:33:49 app: 1,084,707,760

I/AndroidHarness( 8807): INFO AndroidHarness 涓婂崍1:33:49 ctx: 1,084,773,016

W/dalvikvm( 8807): threadid=1: thread exiting with uncaught exception (group=0x401f9760)

E/AndroidRuntime( 8807): FATAL EXCEPTION: main

E/AndroidRuntime( 8807): java.lang.RuntimeException: Unable to retain activity {com.mycompany.mygame/com.mycompany.mygame.MainActivity}: java.lang.NullPointerException

E/AndroidRuntime( 8807): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2928)

E/AndroidRuntime( 8807): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2968)

E/AndroidRuntime( 8807): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3165)

E/AndroidRuntime( 8807): at android.app.ActivityThread.access$600(ActivityThread.java:122)

E/AndroidRuntime( 8807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)

E/AndroidRuntime( 8807): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime( 8807): at android.os.Looper.loop(Looper.java:132)

E/AndroidRuntime( 8807): at android.app.ActivityThread.main(ActivityThread.java:4123)

E/AndroidRuntime( 8807): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 8807): at java.lang.reflect.Method.invoke(Method.java:491)

E/AndroidRuntime( 8807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)

E/AndroidRuntime( 8807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)

E/AndroidRuntime( 8807): at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime( 8807): Caused by: java.lang.NullPointerException

E/AndroidRuntime( 8807): at com.jme3.app.AndroidHarness.onRetainNonConfigurationInstance(AndroidHarness.java:154)

E/AndroidRuntime( 8807): at android.app.Activity.retainNonConfigurationInstances(Activity.java:1545)

E/AndroidRuntime( 8807): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2924)

E/AndroidRuntime( 8807): … 12 more

1 Like

I have the same problem. I have no idea what is wrong.



[java]

public class GameActivity extends AndroidHarness {



public GameActivity() {

appClass = "Game";

eglConfigType = ConfigType.BEST;

exitDialogTitle = "Exit?";

exitDialogMessage = "Press Yes";

eglConfigVerboseLogging= true;

screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

mouseEventsInvertX = true;

mouseEventsInvertY = true;

}

}

[/java]

Try changing appClass to a fully qualified name. Unless you changed the package name in the Main.java file, try the following:

[java]

appClass = "mygame.Main";

[/java]

I’ve tried that. Whatever I put in that field, it fails.

The APK loads on the device, the screen does turn to landscape and then the app dies with logcat logging this “Unable to retain activity” error…

There seem to be issues since r20 of the android SDK.

Can you post more of the log before the error happens?

What version of android are you running?

What version of jme are you using?

Here’s the logcat output:



[java]09-02 02:47:09.946: E/AndroidRuntime(9161): FATAL EXCEPTION: main

09-02 02:47:09.946: E/AndroidRuntime(9161): java.lang.RuntimeException: Unable to retain activity {st.dete.games.lusitanismo/st.dete.games.lusitanismo.MainActivity}: java.lang.NullPointerException

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3090)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3130)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3328)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.access$700(ActivityThread.java:123)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.os.Handler.dispatchMessage(Handler.java:99)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.os.Looper.loop(Looper.java:137)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.main(ActivityThread.java:4424)

09-02 02:47:09.946: E/AndroidRuntime(9161): at java.lang.reflect.Method.invokeNative(Native Method)

09-02 02:47:09.946: E/AndroidRuntime(9161): at java.lang.reflect.Method.invoke(Method.java:511)

09-02 02:47:09.946: E/AndroidRuntime(9161): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

09-02 02:47:09.946: E/AndroidRuntime(9161): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

09-02 02:47:09.946: E/AndroidRuntime(9161): at dalvik.system.NativeStart.main(Native Method)

09-02 02:47:09.946: E/AndroidRuntime(9161): Caused by: java.lang.NullPointerException

09-02 02:47:09.946: E/AndroidRuntime(9161): at com.jme3.app.AndroidHarness.onRetainNonConfigurationInstance(AndroidHarness.java:152)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.Activity.retainNonConfigurationInstances(Activity.java:1567)

09-02 02:47:09.946: E/AndroidRuntime(9161): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3086)

09-02 02:47:09.946: E/AndroidRuntime(9161): … 12 more

[/java]



I’m using Android 4.1 and JME3 nightly.

I’m looking for more of the logcat from before the error happens. Some of the log prints before the error might help.



Is the error on the initial startup of the game?

OK, here’s the full log:



Friendpaste - how to sell viagra online typE



Yes, it’s at start-up time.

At a second glance, it looks like it is having problems loading the base game class.

I tried including the base game both as a JAR and as a project (I am using eclipse) but it keeps failing.

The only I way in which it ends up working is when I create a new Android Lib, lt link its src folder to my game’s src dir and then import it from the android app. But then I get no source code in the debugger :frowning:

OK, I moved the game JAR file into the libs dir in my android project, as per:



http://stackoverflow.com/questions/8645442/android-class-not-found-from-imported-jar-file



Changed JRE compliance level… doesn’t work either.

I’m really getting out of ideas.

OK, I found out I had to put ALL the libs inside the libs dir.



Now I have a NullPointerException somewhere but it seems to be already in my app.



Thanks!

…they are copied when building, something else is wrong. Did you add folders to your libraries settings for that project?

I’ve got the same problem.
I create a BasicGame project, set it to Android, as per instructions in the video.
If I run it on an emulator with hostGPU set, yay I get a blue box and a stats readout.
but run it on my phone (HTC Hero), bleh - Main init failed, NullPointer @ android.view.VieGroup.addViewInner etc etc
boo.

I’m sure it must be something simple, but I’m new to android and jme3-android, and I’ve spent many many hours today trawling the forum, googling, installing plugins and sdk’s, setting up emulators, running helloworld code, recreating the same project half a dozen times…
My head is all fuzzy now so please, could someone just tell me whats wrong and how do I fix it?
On the morrow I shall attempt to borrow a more modern phone and see if it that works.

Examining the error output more closely, I notice this:
E/AndroidConfigChooser( 747): ERROR: Unable to get a valid OpenGL ES 2.0 config, neither Fastest nor Best found! Bug. Please report this.
I installed the Android plugin, opened the android subproject in mobile/ and looked at MainActivity, finding this:
[java]public MainActivity(){
// Set the application class to run
appClass = “gravgame2d.Grav2DMain”;
// Try ConfigType.FASTEST; or ConfigType.LEGACY if you have problems
eglConfigType = ConfigType.BEST;[/java]

So I tried LEGACY, and then FASTEST, both giving this:

D/libEGL ( 794): loaded /system/lib/egl/libGLES_qcom.so D/EGL.oem ( 794): smi: offset=10000000, len=00700000, phys=0x0 D/EGL.oem ( 794): ebi: offset=00000000, len=00800000, phys=0x25800000 D/EGL.oem ( 794): reg: offset=20000000, len=00100000, phys=0xa0000000 W/dalvikvm( 794): threadid=10: thread exiting with uncaught exception (group=0x40018560) E/AndroidRuntime( 794): FATAL EXCEPTION: GLThread 11 E/AndroidRuntime( 794): java.lang.IllegalArgumentException: No configs match configSpec E/AndroidRuntime( 794): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:763) E/AndroidRuntime( 794): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:919) E/AndroidRuntime( 794): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1264) E/AndroidRuntime( 794): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

Original error readout:

I/JmeSystem( 747): INFO JmeAndroidSystem 12:39:58 AM Running on jMonkeyEngine 3.0.0 Beta D/libEGL ( 747): loaded /system/lib/egl/libGLES_android.so D/libEGL ( 747): loaded /system/lib/egl/libGLES_qcom.so D/EGL.oem ( 747): smi: offset=10000000, len=00700000, phys=0x0 D/EGL.oem ( 747): ebi: offset=00000000, len=00800000, phys=0x25800000 D/EGL.oem ( 747): reg: offset=20000000, len=00100000, phys=0xa0000000 I/OGLESContext( 747): INFO OGLESContext 12:40:00 AM Display EGL Version: 1.0 I/AndroidConfigChooser( 747): JME3 using best EGL configuration available here: E/AndroidConfigChooser( 747): ERROR: Unable to get a valid OpenGL ES 2.0 config, neither Fastest nor Best found! Bug. Please report this. E/Application( 747): SEVERE Application 12:40:00 AM Unable to find suitable EGL config D/dalvikvm( 747): GC_EXTERNAL_ALLOC freed 162K, 49% free 2824K/5447K, external 0K/0K, paused 110ms I/AndroidHarness( 747): INFO AndroidHarness 12:40:01 AM Splash Screen Picture Resource ID: 0 I/AndroidHarness( 747): view is null! I/AndroidHarness( 747): Splash Screen Skipped. E/AndroidHarness( 747): Class gravgame2d.Grav2DMain init failed E/AndroidHarness( 747): java.lang.NullPointerException E/AndroidHarness( 747): at android.view.ViewGroup.addViewInner(ViewGroup.java:1975) E/AndroidHarness( 747): at android.view.ViewGroup.addView(ViewGroup.java:1871) E/AndroidHarness( 747): at android.view.ViewGroup.addView(ViewGroup.java:1851) E/AndroidHarness( 747): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:231) E/AndroidHarness( 747): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:221) E/AndroidHarness( 747): at android.app.Activity.setContentView(Activity.java:1668) E/AndroidHarness( 747): at com.jme3.app.AndroidHarness.layoutDisplay(AndroidHarness.java:446) E/AndroidHarness( 747): at com.jme3.app.AndroidHarness.onCreate(AndroidHarness.java:223) E/AndroidHarness( 747): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) E/AndroidHarness( 747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722) E/AndroidHarness( 747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) E/AndroidHarness( 747): at android.app.ActivityThread.access$1500(ActivityThread.java:123) E/AndroidHarness( 747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) E/AndroidHarness( 747): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidHarness( 747): at android.os.Looper.loop(Looper.java:130) E/AndroidHarness( 747): at android.app.ActivityThread.main(ActivityThread.java:3835) E/AndroidHarness( 747): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidHarness( 747): at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidHarness( 747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847) E/AndroidHarness( 747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) E/AndroidHarness( 747): at dalvik.system.NativeStart.main(Native Method)