error starting jinput

this is what I get when I try to run JInput code:


...
Creating Dell USB Keyboard Hub polling = false
Creating Dell USB Keyboard Hub polling = false
Creating Dell USB Keyboard Hub polling = false
java.lang.ArrayIndexOutOfBoundsException: 223
        at net.java.games.input.DirectInputKeyboard.renameKey(DirectInputKeyboard.java:147)
        at net.java.games.input.DirectInputKeyboard.renameKeys(Native Method)
        at net.java.games.input.DirectInputKeyboard.createKeyboard(DirectInputKeyboard.java:205)
        at net.java.games.input.DirectInputEnvironmentPlugin.addDevice(DirectInputEnvironmentPlugin.java:162)
        at net.java.games.input.DirectInputEnvironmentPlugin.enumDevices(Native Method)
        at net.java.games.input.DirectInputEnvironmentPlugin.enumControllers(DirectInputEnvironmentPlugin.java:133)
        at net.java.games.input.DirectInputEnvironmentPlugin.<init>(DirectInputEnvironmentPlugin.java:113)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:498)
        at java.lang.Class.newInstance0(Class.java:350)
        at java.lang.Class.newInstance(Class.java:303)
        at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(DefaultControllerEnvironment.java:208)
        at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:189)
        at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:58)
        at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultControllerEnvironment.java:109)
        at java.security.AccessController.doPrivileged(Native Method)
        at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:107)

Hi

What was the filename of the binary you downloaded?

Cheers

Endolf

jinput-1.1.0-b04-bin-windows.zip

It was a nightly build - downloaded today.

thanks!

Nightly builds are screwed, don’t use them, they are old, very old, and outside of my control.

Use the ones here. They are up to date and include a number of fixes.

HTH

Endolf

I know this topic is old, however, the exception thrown is identical to mine so I’m on topic imo ::slight_smile:

I refuse to give up the great functionality of the older JInput I’m using (yes I start to sound repetetive…). The version including dxinput.dll that is (only one .dll in that version).

My application works, as mentioned several times before, perfect in NetBeans with my gamepad being recognized and behaving as it should. I’ve also semi-solved the loading of the .dll (which was my main issue in earlier posts here, so BIG smile :)). Turned out it wasn’t any problems with the loading part at all! I totally forgot (did not know this) to set the “jinput.plugins” System property to point at the DirectInputEnvironmentPlugin. After doing this, I could run my created JAR, containing my class files, and then receive the exception above. In the folder next to my JAR I have a lib folder containing jinput.jar, jutils.jar and some other JInput jars. Before adding the “jinput.plugins” property I did not see the “Creating Dell USB Keyboard Hub polling = false” part at all.

So now I feel I’ve gotten much closer to a solution; this MUST be possible?! It works great in NetBeans so why wouldn’t it work when running as a JAR?

(I gave up on the latest JInput version, had to make non-trivial changes in my code (which I don’t mind in general) but never got the wanted result. Perhaps its just the way I developed my app; I feel it works much much smoother / simpler when using the old Axis class.)

Please, any help would be much appreciated, I can’t be far off now :slight_smile:

Here is the code I use at the top of the application’s main class:


static {
        try {
            System.setProperty("java.library.path", "C:/TEST/NativeDebug/lib/native/dxinput.dll");
            System.setProperty("jinput.plugins", "net.java.games.input.DirectInputEnvironmentPlugin");
            System.load("C:/TEST/NativeDebug/lib/native/dxinput.dll");            
        }
        catch(Exception e) {
            System.out.println("Error loading library: " + e);
        }
}

Thanks!

/ Anders

Hi

If you never saw the “Creating Dell USB Keyboard Hub polling = false” before (even in netbeans), then jinput wasn’t configured correctly, it looks as though you have it right now, and it has now revealed the bug. You have 2 choices, either fix the bug in the ancient version of jinput you have, or upgrade. The stack trace will show you where it’s going wrong. I took the conscious decision that supporting multiple versions of jinput (the old style 1.0 and the new 2.0) is not practical, so I won’t apply a patch to the old one. With some clever digging in CVS you’ll be able to see how I fixed it before anyway :slight_smile: (and I might even give you some clues later, got to run to work now though)

HTH

Endolf

So the bug reveals itself when trying to run app as a JAR? Forget what I said about never seeing “…polling = false…”. This + all my connected devices shows up when running my app in NetBeans (everythings works :)) so no bug there(?).

This error first comes to surface when running my created JAR. Is this “JAR/older JInput version” issue a known bug? Sorry for asking the same thing over and over, I just can’t accept (well) that the older JInput version(s) are only runnable in an IDE?

Correct me if I’m wrong, and if you can, cheer me up some 8)

/ Anders

If it works in the IDE, it will work outside, it sounds to me like different jars/dlls are being used somewhere.

Endolf

Your last comment is encouraging, plus it’s only logical that it should work in both cases (if first one is true). That said, I would have been up for some code digging if that was my only option.

Will go at it again after a nutrious pizza, thanks for your replies :slight_smile:

/ Anders

Wish I could say problem solved, but this one is just i n s a n e >:(

As mentioned I use NetBeans but I wanted to try the JAR creating in Eclipse, so I made a small JInput test project there. After importing/adding all the needed jars, jinput.jar jutils.jar etc etc, I tried to run the project. Then I get the same exception as above, which I also got from my created JAR in NetBeans.

So I have the following results when trying to run this project:

  • NetBeans 5.5.1
  • running inside IDE: perfect result, no problems at all
  • running created JAR: causing the exception above
  • Eclipse
  • running inside IDE: causing the exception above

SO what the heck is the problem? Been trying to figure out exactly how NetBeans compiles/loads/runs a project to maybe gets some clues, but it’s confusing. And so unbelievably annoying. The days go by. It’s not an appealing thought to give up on this when it IS actually working, running in NB. Don’t really know which way to go from here, but I want to post my simple code + the Ant build file NB uses…if anyone could take a look at this I would be grateful, perhaps I missed something obvious. Last try. Sorry if I’m a bit off topic.

NetBeans build.xml (works when running in NB, not working correct when running created JAR):


<?xml version="1.0" encoding="UTF-8"?>
<project name="NativeDebug" default="default" basedir=".">
    <description>Builds, tests, and runs the project NativeDebug.</description>
    <import file="nbproject/build-impl.xml"/>

    <!-- ===================== Property Definitions =========================== -->
    
    <property name="controllerexample.mainclass" value="com.example.ControllerExample"/>

    <property name="app.name"     value="NativeDebug"/>

    <!-- Load the property app.version from the file which is itself specified by the property app.version
    The version number is used for various output files. -->
    <property file="version"/>

    <!-- This is the working directory for the compilation and jar file generation. --> 
    <property name="build.home"   value="build"/>  

    <!-- This is the target directory for the class files -->
    <property name="classes.home" value="${build.home}/classes"/>
  
    <!-- This is the directory to be used for certain tasks which need a temporary directory. -->
    <property name="scratch.home" value="${build.home}/scratch"/>

    <property name="dist.home"     value="dist"/>

    <!-- This is the directory where all kinds of supporting libraries reside. -->
    <property name="lib.home"	 value="lib"/>  
    
    <!-- This is the directory where all external libraries reside which are neccessary when compiling or running the app. -->
    <property name="runtime.lib.home"     value="${lib.home}/runtime"/>

    <!-- Specifies the directory where the JInput plugins (jar files) reside. -->
    <property name="plugin.lib.home"     value="${lib.home}/plugin"/>

    <!-- Specifies the directory where the unpacked native libraries are. The unpacked native libraries are needed to run the app. -->
    <property name="native.lib.home" value="${lib.home}/native"/>
  
    <!-- This is the directory which contains the app's source code. -->
    <property name="src.home"      value="src"/>

    <!-- name of the output .jar file -->
    <property name="jar.name" value="jarfile.jar" />    

    <!-- The filename of the jar file which contains the classes. -->
    <property name="classes.jar.name" value="${app.name}-${app.version}.jar"/>

    <!-- The filename of the Jar file containing the resources. -->
    <property name="resources.jar.name" value="${app.name}-resources.jar"/>
  
    <!-- The file name of the source distribution. -->
    <property name="srcdist.file.name" value="${app.name}-${app.version}-src.zip"/>

    <!-- The top folder name inside the source distribution. -->
    <property name="srcdist.dir.name" value="${app.name}-${app.version}-src"/>

    <!-- ===================== End Property Definitions ======================= -->

    <!-- ==================== External Dependencies =========================== -->

    <!-- The fileset containing everything which selects everything that is needed to form the source distribution. -->
    <fileset id="srcdist.files" dir="${basedir}" >
    <include name="*.*"/>
   
    <!-- do not copy own build.properties -->
    <exclude name="build.properties"/>
   
    <include name="${lib.home}/**/*.*"/>
   
    <include name="${src.home}/**/*.*"/>
   
    <!-- Exclude any class files which may have been generated in the source code directory.  
           This happens when NetBeans is used as IDE. -->
    <exclude name="${src.home}/**/*.class"/> 
    </fileset>  

    <!-- This fileset contains everything that is needed to run the application. -->
    <fileset id="runtime.lib.files" dir="${runtime.lib.home}">
       <include name="*.jar"/>
    </fileset>
    
    <!-- This fileset contains the JInput plugins -->
    <fileset id="plugin.lib.files" dir="${plugin.lib.home}">
       <include name="*.jar"/>
    </fileset>
   
    <!-- ==================== Init Target ================================== -->

    <!-- Init creates the timestamp. -->
    <target name="init">
       <tstamp/>
       <mkdir dir="${scratch.home}"/>
    </target>
    
    <!-- ==================== Compilation Classpath =========================== -->

    <!-- This builds the classpath which is needed when the source gets compiled. -->

    <path id="compile.classpath">
       <fileset refid="runtime.lib.files"/>
    </path>

    <!-- This builds the classpath containing the JInput plugins. -->
    <path id="plugin.classpath">
       <fileset refid="plugin.lib.files"/>
    </path>

    <!-- ==================== Compile Target ================================== -->
    
    <target name="compile" depends="init" description="Compiles the sourcecode.">
      
      <mkdir  dir="${classes.home}"/>

      <!-- compile with given parameters -->
      <javac srcdir="${src.home}"
          destdir="${classes.home}">          
          <classpath refid="compile.classpath"/>
      </javac>
    </target>
    
    <!-- ==================== Create JAR ================================== -->   
       
    <target name="jar" depends="compile,-pre-jar" description="Create jar and MANIFEST.MF">

      <!-- create a property containing all .jar files, prefix lib/, and seperated with a space -->
      <pathconvert property="libs.project" pathsep=" ">
        <mapper>
          <chainedmapper>
            <!-- remove absolute path -->
            <flattenmapper />
            <!-- add lib/ prefix -->
            <globmapper from="*" to="lib/*" />
          </chainedmapper>
        </mapper>

        <path>
          <!-- lib.home contains all jar files, in several subdirectories -->
          <fileset dir="${lib.home}">
            <include name="**/*.jar" />
          </fileset>
        </path>
     </pathconvert>

     <!-- create the jar -->
     <jar jarfile="${build.home}/${jar.name}" basedir="${build.home}/classes">

       <!-- define MANIFEST.MF -->
       <manifest>
         <attribute name="Built-By" value="Anders" />
         <attribute name="Main-Class" value="com.example.ControllerExample" />
      
         <attribute name="Class-Path" value="${libs.project}" />
       </manifest>
     </jar>  

     <!-- ==================== Create JAR Dist ================================== -->
    
     <delete dir="${dist.home}" />

     <!-- contains all library dependencies -->
     <mkdir dir="${dist.home}/lib" />

     <copy todir="${dist.home}" file="${build.home}/${jar.name}" />
     <copy todir="${dist.home}/lib" filtering="off">

     <!-- remove the directory hierarchy: lib contains no subdirectories -->
     <flattenmapper />
     <fileset dir="${lib.home}" includes="**/*.jar" />
     </copy>
    
    </target>

    <!-- ======================== Run Target ================================= -->

    <target name="run" depends="compile, -determinePlugin">  		
       <java fork="true" classname="${controllerexample.mainclass}" taskname="">
         <classpath>
	<path refid="compile.classpath"/>
                <path refid="plugin.classpath"/>
	<pathelement path="${classes.home}"/>
                <pathelement path="${src.home}"/>
        </classpath>
        <!-- TEMP these are set in java class..... -->
        <!-- <sysproperty key="java.library.path" value="${basedir}/${native.lib.home}"/> -->            
        <!-- <sysproperty key="jinput.plugins" value="${jinput.plugins}"/>  -->
      </java>
    </target>
  
    <target name="-determinePlugin">
      <condition property="jinput.plugins" value="net.java.games.input.DirectInputEnvironmentPlugin">
                <os family="windows"/>
      </condition>
      <condition property="jinput.plugins" value="net.java.games.input.OSXEnvironmentPlugin">
	<os family="mac"/>
      </condition>
      <condition property="jinput.plugins" value="de.bitecode.input.linux.LinuxInputEnvironmentPlugin">
	<and>
                    <os name="Linux"/>
                    <isset property="altplugin"/>
	</and>
      </condition>
      <condition property="jinput.plugins" value="net.java.games.input.LinuxEnvironmentPlugin">
	<os name="Linux"/>
      </condition>		
    </target>

    <target name="ControllerExample"
	description="starts example application">
               <property name="mainclass" value="${controllerexample.mainclass}"/>		
  	     <antcall target="run"/>
     </target>
</project>

My one and only main class:


package com.example;

import net.java.games.input.Axis;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;

public class ControllerExample 
{   
    static {
        try {
            System.setProperty("java.library.path", "C:/TEST/NativeDebug/lib/native/dxinput.dll");
            System.setProperty("jinput.plugins", "net.java.games.input.DirectInputEnvironmentPlugin");            
        }
        catch(Exception e) {
            System.out.println("Some error: " + e);
        }
    }
    
    public ControllerExample() 
    {
    }
    
    private void showControllers()
    {   
        System.out.println("Java Lib Path: " + System.getProperty("java.library.path"));
        System.out.println("Java Class Path: " + System.getProperty("java.class.path"));
        try {
            // accesses the default controller environment which contains all identified controllers                
            ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
            // retrieve the available controllers
            Controller[] controllers = ce.getControllers();
                                       
            for(int i = 0; i < controllers.length; i++) {                
                System.out.println("Index: " + i + " - Controller type: " + controllers[i].getType() + " - Controller name: " + controllers[i].getName());
            }
        }
        catch(Exception e) {
            System.out.println("An error occurred: " + e);
            e.printStackTrace();
        }        
    }
    
    public static void main(String[] args)
    {
        new ControllerExample().showControllers();
    }
}

  • Classpath value above, when running in NB, is:

Java Class Path: C:\TEST\NativeDebug\lib\runtime\jinput.jar;C:\TEST\NativeDebug\lib\runtime\jutils.jar;C:\TEST\NativeDebug\lib\plugin\linux-eventinterface-jinput-plugin-0.1.jar;C:\TEST\NativeDebug\lib\plugin\linux.jar;C:\TEST\NativeDebug\lib\plugin\win32-x86-directinput-plugin.jar;C:\TEST\NativeDebug\build\classes;C:\TEST\NativeDebug\src

  • And when running created JAR from command line, it is:

jarfile.jar (name of my JAR…)

Have also tried setting java.class.path to the above (in ControllerExample.java) and some other values, but no luck…

  • Run command used:

java -jar jarfile.jar

THANK YOU very much :slight_smile:

/ Anders

Oh God…

I tried it ONE last time just now, seeing that the manifest file was created by “1.5.0_08-b03 (Sun Microsystems Inc.)”. I then used java -jar jarfile.jar command of my jre1.5.0_08 installation.

It worked ;D

Which of course could mean a bad thing that I’m too tired to think of right now…ups and downs.

/ Anders

OK:

How do I make my old JInput version work with Java 1.6, currently the only way to avoid the above exception is to run JAR with Java 1.5 (which it was compiled with)… :-\

If my only option now is to modify the old JInput sources and recompile them to get rid of the bug, which classes are of interest? How much work am I looking at? Clues and hints provided by Endolf? :stuck_out_tongue:

The easy way is not an option for me, I’m too ignorant for that.

/ Anders

EDIT

I’m digging in CVS as we speak; which CVS revision # applies to my ancient JInput version? 1.1.2.1? Looking at DirectInputEnvironmentPlugin.java right now, trying to spot changes. Can you please point me in a direction where I will have a chance to fix this issue? Naturally it takes some time for me to learn how the different classes/methods work. Need I modify more classes?

I really appreciate your patience with me, desperately clinging on to the past… looks like a fun challenge though :slight_smile:

Have a great evening!

/ Anders

I actually got my little example above (ControllerExample.java) to work now, no matter what JRE version used to run the code :slight_smile: No more ArrayIndexOutOfBoundsException: 223, no exceptions at all. Compiled with jdk1.6.0_07. I must learn to always use latest version…

What I did was just to comment out 1 loc in DirectInputEnvironmentPlugin.java…


private void addDevice(...)
{
    ...

    if(category == 19) {
        //c = DirectInputKeyboard.createKeyboard(lpDevice, subtype, productName, instanceName);
    }

    ...
}

This is great news for me; been struggling with this for too long. I might even be able to enjoy the Iron Maiden concert tonight, now 8)

/ Anders


System.setProperty("java.library.path", "C:/TEST/NativeDebug/lib/native/dxinput.dll");

should be

System.setProperty("java.library.path", "C:/TEST/NativeDebug/lib/native");

Thanks, I got it working though :slight_smile:

Running created JAR (compiled with JDK 1.5 or 1.6) with JRE 1.6, no problems. At last!

/ Anders

I like problems that solve themselves when I’m away for the weekend :slight_smile:

You realise by commenting out that line you won’t get Jinput controlling keyboards?, if that doesn’t worry you, go for it. I’m still a little unsure as to what the problems are with upgrading though, it should be more or less backward compatable. (unless there is something in the past I forgotten about, which is more than possible)

Endolf

Yes I get that, was a deliberate decision. I want only the gamepad functionality, that’s it :slight_smile: At least in this project. I have not put a great deal of time into finding the cause of why running with JRE 1.6 would throw AIOoB exception. I was just thrilled to see my first attempt (uncommenting) do the trick for me. As I said before: it’s a blessing to be able to use the old Axis class, instead of the newer counterparts. At least the way I have written my code (which could be improved a LOT I’m sure 8)). In future projects I will of course use latest version from the start. Just felt a little short on time and wanted to complete this project. Unfinished projects are not acceptable in my book :slight_smile:

Thanks all for your help!

/ Anders