• Register
search
Log In
0 votes
127 views

Problem :

I am working on a card game, and currently running into an error when I run it in eclipse. I am also using slick 2d.

Here is the error

java.lang.runtimeexception: no opengl context found in the current thread.

6.9k points

2 Answers

0 votes

Solution :

Depending on which LWJGL you're using, init your Display as shown bellow:

LWJGL 3 

if (!glfwInit()) {
   throw new IllegalStateException("Can't init GLFW");
}

LWJGL 2:

try {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.create();
} catch (LWJGLException ex) {
   Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

Please dont forget Display.create() .

Further Readings:

https://github.com/nifty-gui/nifty-gui/issues/111

36.1k points
edited by
0 votes

Solution:

This kind of error is common for LWJGL starters. The OpenGL context gets bound to a thread when it's been created. So you can only access this context from the same thread.

Explanation:

As it does not look that you're working with different threads there might be another cause. Slick2D seems to need a valid OpenGL context for its Image class.

So my first try would be to initialize an OpenGL context before initializing your card images.

Another Reason for occuring this error may be

This happened to me once, and I couldn't figure out what to do until I realized I was calling the image loader before OpenGL had initialized. Make sure that you aren't defining any variables with an image loader in the constructor(or any other method called) before OpenGL inits(what I did).

If you are not able to find solution yet then try this

In lwjgl 3.x and higher

GLContext.createFromCurrent();

If you're using libgdx, there is also

Gdx.app.postRunnable(...)

to post a

Runnable

on the render thread.

 

You can add old thread depending on which LWJGL you're using, init your Display:

LWJGL 3 (uses GLFW):

if (!glfwInit()) {
   throw new IllegalStateException("Can't init GLFW");
}

LWJGL 2:

try {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.create();
} catch (LWJGLException ex) {
   Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

 

Never forget 
Display.create() :)

 

12.8k points

Related questions

0 votes
1 answer 194 views
194 views
Problem : I am getting the run time exception in my program while I am reading a file through a Scanner. exception in thread "main" java.util.nosuchelementexception: no line found
asked Oct 23, 2019 peterlaw 6.9k points
1 vote
1 answer 17 views
17 views
Problem: I am a begginer in java programming language and I have been coding for just some days. To practice my programming I wrote this code in java: public class Main { public static void main(String[] argv){ int 2count, h-l, a/b, } } But It shows me the error message ... , . expected Syntax error on token ",", ;expected at Main.main(Main.java:3) Whats is wrong in my code can anyone help me out?
asked Apr 6 LizzyM 5.7k points
1 vote
1 answer 16 views
16 views
Problem : I have very recently started to learn programming in Java. I am trying to execute my java code but I am facing the below error. “Exception in thread "main" java.lang.arrayindexoutofboundsexception:” I am unable to understand above error. Please find below my code: ... according to my debugger*/ myodd[j] = input[i]; j++; } return myodd; } Please help me in fixing above error.
asked Mar 30 morrisBson 3.2k points
1 vote
1 answer 22 views
22 views
Problem: I got error while applying weblogic patch useing bsu.sh: patch_download_dir=$FMW_HOME/utils/bsu/cache_dir -patchlist=GFWX -prod_dir=$FMW_HOME/wlserver_10.3 -log=$FMW_HOME/utils/bsu/bsu_weblogic.log Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded ... .bea.plateng.patch.Patch.main(Patch.java:281) Can anyone explain me this and help me to solve this error?
asked Mar 27 LizzyM 5.7k points
0 votes
1 answer 70 views
70 views
I wrote a java code that gives some error: Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43) at org.hibernate.boot.MetadataSources.< ... .initializeBean(AbstractAutowireCapableBeanFactory.java:1700) ... 25 common frames omitted Can anyone help me out with this?
asked Mar 12 LizzyM 5.7k points