Null pointer in Jinput Test program

Hi im trying my hardest to get JInput working here and its not doing any good for my mental health >:

ive unzipped the core package into “jdk1.5.0_01\jre\lib\ext”

with jinput.jar and jutil.jar in the ext directory and the dxinput.dll and dxinput.jar in a folder named “controller” as the intro tutorials says.

i navigate to the “jdk1.5.0_01\jre\lib\ext” directory in the command window and execute the command:

java -cp jinput.jar;jutils.jar net.java.games.input.test.ControllerTextTest


C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext>java -cp jinput.jar;jutils.jar net
.java.games.input.test.ControllerTextTest
Controller Env = net.java.games.input.DefaultControllerEnvironment@35ce36
Scanning jar: dxinput.jar
Examining file : META-INF/
Examining file : META-INF/MANIFEST.MF
Examining file : net/
Examining file : net/java/
Examining file : net/java/games/
Examining file : net/java/games/input/
Examining file : net/java/games/input/DirectInputAxis.class
Examining file : net/java/games/input/DirectInputDevice.class
Examining file : net/java/games/input/DirectInputEnvironmentPlugin.class
Found candidate class: net/java/games/input/DirectInputEnvironmentPlugin.class
Exception in thread "main" java.lang.NoClassDefFoundError: IllegalName: net/java
/games/input/DirectInputEnvironmentPlugin
        at java.lang.ClassLoader.preDefineClass(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at net.java.games.util.plugins.Plugins.processJar(Plugins.java:112)
        at net.java.games.util.plugins.Plugins.scanPlugins(Plugins.java:85)
        at net.java.games.util.plugins.Plugins.<init>(Plugins.java:73)
        at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(D
efaultControllerEnvironment.java:174)
        at net.java.games.input.DefaultControllerEnvironment.scanControllers(Def
aultControllerEnvironment.java:164)
        at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultC
ontrollerEnvironment.java:57)
        at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultContro
llerEnvironment.java:108)
        at java.security.AccessController.doPrivileged(Native Method)
        at net.java.games.input.DefaultControllerEnvironment.getControllers(Defa
ultControllerEnvironment.java:106)
        at net.java.games.input.test.ControllerTextTest.<init>(ControllerTextTes
t.java:54)
        at net.java.games.input.test.ControllerTextTest.main(ControllerTextTest.
java:86)


ive tried using the -D option with the jinput.plugins option but java tells me the class doesn’t exist

can anyone help me with this, and can anyonne make the install for this a little less painful maybe a complete introduction to jinput not an introduction scattered over many threads, it’s just messy!!

[quote]Ive tried using the -D option with the jinput.plugins option but java tells me the class doesn’t exist
[/quote]
do not use the property if you have copied the plugin jar into the controller directory. the two approaches are mutual exclusive.

Hi i’ve tried a lot of things with the -D, without the -D

just trying


java -cp jinput.jar;jutils.jar net.java.games.input.test.ControllerReadTest

gives me the same error

i can get rid of the error by unpacking the dxinput.jar and deleting the dxinput.jar.

There seems to be a bug with the plugin classloader when reading form jar files as i used the plugin code for a project last year and had the same problems.

So with the jar unpacked the demo now runns but only a blank JFrame appears ???

is Jinput not finding the dll’s or something i wonder??

JInput (in fact its is JUtils where the PluginClassLoader lives) does some strange stuff. I tend to avoid this strange plugin system at all and simply call:

This assumes that the native library (e.g. dxinput.dll) is in the directory from where you are calling this.
Jeff’s plugin mechanism may be nice but IMHO causes to much hassle especially if you have multiple JVMs installed.

The names of the plugin classes are listed on the introduction page.

Ok i removed the “controller” directory and moved the
dxinput.dll and dxinput.jar to my project directory.

Im using netbeans (i also tried from the command line) so i set my Running Projecct Arguments to


-Djava.library.path=. -Djinput.plugins=net.java.games.input.DirectInputEnvironmentPlugin

and the jinput.jar and jutils.jar are both in the


{java_home}/jre/libs/ext directory

and im running this code


/*
 * InputManager.java
 *
 * Created on 10 January 2005, 19:04
 */

import net.java.games.input.*;

/**
 *
 * @author Preacher
 */
public class InputManager {
  
  Keyboard kb = null;
  
  public static void main(String[] args){
    new InputManager();
  }
  
  /** Creates a new instance of InputManager */
  public InputManager() {
    
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cont = ce.getControllers();
 
    System.out.println("cont: " + cont.length);
     for (int i = 0; i < cont.length; i++) {
       if (cont[i].getType() == cont[i].getType().KEYBOARD) {
         kb = (Keyboard) cont[i];
      }
    }
    
    for(int i = 0; i < 100000; i++) {
      update();
    }
    
    System.out.println("done..."); 
    
  }// end constructor
  
  public void update(){
    
    kb.poll();
    
    Axis[] ax = kb.getAxes();
    
    for (int x = 0; x < ax.length; x++) {
      float num = ax[x].getPollData();
      if (num != ax[x].getDeadZone()) {
        if (ax[x].getName().equalsIgnoreCase("key 110")) {
          System.out.println("up arrow");
        }
      }
    } 
    
  }
  
}// end class 

and its not reading any controllers still and therefore throwing a null pointer when i try to poll the keyboard

any idea why its still not working??
sorry about all this it’s just really annoying. Think i’ll write a tutorial for jiput afte all this :slight_smile:

If don’t you see this part on your console

 Examining file : META-INF/
Examining file : META-INF/MANIFEST.MF
Examining file : net/
Examining file : net/java/
Examining file : net/java/games/
Examining file : net/java/games/input/
Examining file : net/java/games/input/DirectInputAxis.class

. . . . . . and some more text

I’m pretty (almost) sure that it doesn’t find the plugin.

@Preacher:

hi,
you asked me how I fixed my problems with jinput. . .
The solution was to build the whole thing by myself.

You assumed the problem is in the plugin classloader in utils.jar --> you’re right

java.lang.NoClassDefFoundError: IllegalName: net/java/games/input/DirectInputEnvironmentPlugin

The problem is that the plugin loader uses slashes to specify the path/filename (only dots are allowed)

The code, wich you can check out from CVS, is fine. I built it and everything was fine. I don’t know if someone updated the binaries meanwhile.

my file hierarchy looks like this:

./dxinput.dll
./jinput.jar
./utils.jar
./Controller/dxinput.jar
./standard/ /* here are some testfiles*/

./ is the root from where my program is executed

this post might be useful for you too (the plugin problem):
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jinput;action=display;num=1098543727

[quote] im trying my hardest to get JInput working here and its not doing any good for my mental health >:
[/quote]
. . . it wasn’t good for mine either

The thing is that i can get the "ControllerReadTest " up and running, but its just a blank JFrame, i presume theres supposed to be a read out of the keyboard and the mouse or something.

So the DirectInputEnvironmentPlugin mustn’t be loading then as the code below is not printing out when i start the ControllerReadTest


Examining file : META-INF/
Examining file : META-INF/MANIFEST.MF
Examining file : net/
Examining file : net/java/
Examining file : net/java/games/
Examining file : net/java/games/input/
Examining file : net/java/games/input/DirectInputAxis.class 

and just to reiterate im typing this at the command line


C:\jinput>java -cp jutils.jar;jinput.jar -Djava.library.path=. net.java.games.in
put.test.ControllerReadTest

and my directory structure follows mk81’s except that to overcome the error where the plugin loader doesn’t find the DirectInputEnvironmentPlugin class i’ve unpacked the dxinput.jar.

./dxinput.dll
./jinput.jar
./utils.jar
./Controller/net/java/games/input/ *.class

Do you have a bug fixed version of jutils.jar mk81?? as would really appretiate it if i could use it to load the plugins

The fix for the 1.5 incompatabiltyi as uplaoded some tiem ago.

However I did that with 1.5 beta. The final JDK1.5 broke somethign ELSE on me that kept it from compiling, s oI just uplaoded a fix for that so it can all compile again.