Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when not using default game View on Android #7465

Closed
obigu opened this issue Sep 24, 2024 · 0 comments · Fixed by #7475
Closed

Crash when not using default game View on Android #7465

obigu opened this issue Sep 24, 2024 · 0 comments · Fixed by #7475
Labels
Milestone

Comments

@obigu
Copy link
Contributor

obigu commented Sep 24, 2024

#7004 seems to have introduced a bug that crashed apps on startup that don't use default libGDX View due to the following ClassCastException.

java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.FrameLayout
                                                                                                    	at com.badlogic.gdx.backends.android.DefaultAndroidInput.createDefaultEditText(DefaultAndroidInput.java:762)
                                                                                                    	at com.badlogic.gdx.backends.android.DefaultAndroidInput.access$100(DefaultAndroidInput.java:71)
                                                                                                    	at com.badlogic.gdx.backends.android.DefaultAndroidInput$3.run(DefaultAndroidInput.java:209)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

The error comes from the following libGDX snippet on DefaultAndroidInput:

private void createDefaultEditText () {
		View view = ((AndroidGraphics)app.getGraphics()).getView();
		FrameLayout frameLayout = (FrameLayout)view.getParent();

in which it assumes the view uses a FrameLayout but that may not be the case.

Can reproduce on 1.12.2-SNAPSHOT by initializing a game with custom layout such as this one that uses RelativeLayout with 2 Views or anything other than a FrameLayout:

View gameView = initializeForView(game, config);
		View bannerAdView = bannerService.setup();
		RelativeLayout layout = new RelativeLayout(this);
		layout.addView(gameView);
		layout.addView(bannerAdView);
		setContentView(layout);

Pinging @Berstanio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant