Reputation: 135
I hope you can help me and I hope I did not overlook any relevant answers.
So I get this Exception when I try and run my DesktopLauncher.java class.
Executing: gradle run
Configuration on demand is an incubating feature.
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:core:compileJava
:core:processResources UP-TO-DATE
:core:classes
:core:jar
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:desktop:compileJava
:desktop:processResources UP-TO-DATE
:desktop:classes
Exception in thread "LWJGL Application" java.lang.ClassCastException: com.bluemoon.game.MainGame cannot be cast to com.badlogic.gdx.InputProcessor
at com.bluemoon.game.MainGame.create(MainGame.java:30)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
:desktop:run
BUILD SUCCESSFUL
Total time: 4.267 secs
I just copied the my code from this tutorial.
This is my MainGame.java from the core files
package com.bluemoon.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
public class MainGame extends ApplicationAdapter {
Texture img;
TiledMap tiledMap;
OrthographicCamera camera;
TiledMapRenderer tiledMapRenderer;
@Override
public void create () {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false,w,h);
camera.update();
tiledMap = new TmxMapLoader().load("basic_map.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
Gdx.input.setInputProcessor((InputProcessor) this);
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
}
}
And this is my DesktopLauncher.java
package com.bluemoon.game.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.bluemoon.game.MainGame;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.fullscreen = true;
cfg.resizable = false;
new LwjglApplication(new MainGame(), cfg);
}
}
When I run the DesktopLauncher.java, the program is built, then the screen turns black (probably because it's going into full screen mode). After about 1-2 seconds the program crashes.
I'm using gradle a packet management system, if that's important.
Upvotes: 0
Views: 611
Reputation: 7374
It is because MainGame
class doesn't implement InputProcessor
class. It should be:
public class MainGame extends ApplicationAdapter implements InputProcessor {
Of course, you will have to implement all methods from InputProcessor.
Upvotes: 1