javaintellij-ideaopenglslick2dtiled

java ThiledMap slick No OpenGL context found in the current thread


I want to use .tmx file as TiledMap

this is my main class:

package com.company;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

public class Main {

    private static TiledMap map;
    public static void main(String[] args) {
        try {
            init();
        }
        catch (SlickException e) {
            e.printStackTrace();
        }
    }
    private static void init() throws SlickException {
        map = new TiledMap("com/company/untitled.tmx");
        map.render(100,100);
    }
}

I have the follow problem when I'm compile my program in intellij:

Tue Jun 20 23:37:23 IRDT 2017 ERROR:No OpenGL context found in the current thread. java.lang.RuntimeException: No OpenGL context found in the current thread. at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124) at org.lwjgl.opengl.GL11.glGetError(GL11.java:1377) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:226) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:171) at org.newdawn.slick.Image.(Image.java:196) at org.newdawn.slick.tiled.TileSet.(TileSet.java:113) at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:447) at org.newdawn.slick.tiled.TiledMap.(TiledMap.java:90) at org.newdawn.slick.tiled.TiledMap.(TiledMap.java:77) at com.company.Main.init(Main.java:18) at com.company.Main.main(Main.java:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)


Solution

  • You can't simply start rendering in the init method. You should override the render method and do the rendering there. At that point the OpenGL context should have been initialized by Slick2D.

    public void render(GameContainer arg0, Graphics arg1) throws SlickException