NullPointerException and GL11.glGetString

Hi, sorry if it’s a beginner’s problem, but when i try tu run this very small code :

import java.lang.System;
import org.lwjgl.opengl.GL11;

public class Version {

	public static void main(String[] args) {
		Version v = new Version();
		v.version();
	}

	void version() {
		String version;
		version = GL11.glGetString(GL11.GL_VERSION);
		System.out.println(version);
	}

}

I get an NullPointerException.

Exception in thread "main" java.lang.NullPointerException
	at org.lwjgl.opengl.GL11.glGetString(GL11.java:1556)
	at Version.version(Version.java:13)
	at Version.main(Version.java:8)

This line doesn’t want to compile : version = GL11.glGetString(GL11.GL_VERSION);

Did i have forgot something ?

Thanks (and sorry for my english, i’m a french beginner).

need to create a context first (or display)

Thanks ! It works when i create a display, but i only want to create a context (because when i create a display, a black screen appears fastly and disapear and i don’t want this screen). But how can i create a context ? I can’t import the Context class and i don’t know how to create the context with the ContextCapabilities class.

You could try creating a pbuffer instead.

Cas :slight_smile:

Thanks, but i’ve tried that :

import java.lang.System;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;

public class Version {

	public static void main(String[] args) {
		Version.version();
	}

	public static void version() {
		String version = null;
		String vendor = null;

		try {
			Drawable pb = null;
			Pbuffer buffer = new Pbuffer(0, 0, null, null, pb);

		} catch (LWJGLException e) {
			e.printStackTrace();
		}
		version = GL11.glGetString(GL11.GL_VERSION);
		vendor = GL11.glGetString(GL11.GL_VENDOR);
		System.out.println(version);
		System.out.println(vendor);
	}

}

And i get :

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  SIGSEGV (0xb) at pc=0xb78ba511, pid=11927, tid=3086760416
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_02-b09 mixed mode, sharing)
# Problematic frame:
# V  [libjvm.so+0x173511]
#
# An error report file with more information is saved as hs_err_pid11927.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

???

I changed the PixelFormat argument of the Pbuffer constructor which was null, by a good PixelFormat and i don’t get the error of the JVM, but now i have the NullPointerException again.
Or maybe i’ve forgotten something ?

Edit : oh sorry, i’ve forgotten the makeCurrent() method :-[
I’m really sorry for my very bad level in LWJGL, but 'ive started to learn this very very good API yesterday.

Well, using it in a headless environment, where you have to manually create a pbuffer and make it current, isn’t exactly the easiest way to use lwjgl & opengl - so that you managed to find those errors by yourself, is actually pretty good :slight_smile:

happy coding ;D