Home Features Docs Blog Support GitHub

Gdx.net.openURI runtime error in GLKView libgdx app


(Herman Tse) #1

Hi,

I created my libgdx application as a IOSGLKViewApplication in a view of GLKView. I tried to call Gdx.net.openURI in my libgdx application. It works on Android side but have runtime error on iOS side with error message:
java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean apple.uikit.UIApplication.canOpenURL(apple.foundation.NSURL)’ on a null object reference

Any idea? Is it because I’m not creating libgdx application as IOSApplication and so the Gdx.net object is not properly initialised? Any suggestion is welcomed.

I’m using libgdx 1.9.8, moe-gradle 1.4.3

Thanks and Regards,
Herman


(Herman Tse) #2

Hi,

I found more info after tracing the source code. When initiating the libgdx app as IOSGLKViewApplication (which extends IOSApplication), when calling initializeForView(), only the IOSApplicatoin.init() is called where IOSApplication.didFinishLaunching is not called beforehand and thus the private member uiApp is not initialised. When the private IOSNet member net is initiated in IOSApplication.init() method, the constructor of IOSNet will keep the uiApp (which is not initialized). When the openURI is called, uiApp.canOpenURL is called and thus causing the runtime exception of ‘Attempt to invoke virtual method … on a null object reference’. The null object reference refers to the private member uiApp under IOSApplication.

However, I don’t know how to fix it. Any idea?

Thanks and Regards,
Herman


(Herman Tse) #3

I made a workaround by introducing platform specific code. For iOS, I call UIApplication.sharedApplication().openURL(NSURL.URLWithString(url)). For Android, I call Gdx.net.openURI as usual.

Cheers


Launch a libgdx game using MOE from iOS storyboard?