Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Posted
2005-05-31 11:13:37 » |
|
I'm having much trouble running JInput with a gamepad. When I call getControllers() it returns an empty array following is my code: /* * Bestuuring.java * * Created on 12 mei 2005, 10:14 */
package idp1;
import net.java.games.input.*; import net.java.games.util.plugins.*;
/** * * @author Groep15 */ public class Bestuuring extends Thread { private net.java.games.input.Controller gp; public Bestuuring() { System.out.println("bestuuring online"); ControllerEnvironment ce = DirectInputEnvironmentPlugin.getDefaultEnvironment(); // retrieve the available controllers net.java.games.input.Controller[] controllers = ce.getControllers(); //this gives an empty array if (controllers.length == 0) { System.out.println("controllers == null"); } else { System.out.println("controllers found"); } net.java.games.input.Controller c; gp = null; for (int i = 0; i < controllers.length; i++) { c = controllers; if(c.getType() == net.java.games.input.Controller.Type.GAMEPAD) { // c is a gamepad gp = controllers; } } } public void run() { //not yet coded, no need because the constructor doesn't work } private void errorHandler(String message) { Main.stuur.append("e" + message); //works fine } } I'm running on Windows XP with NetBeans 4 and J2sdk1.4.2 Could someone please give me some advice? Grtz, Foppie
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
Jeff
|
 |
«
Reply #1 - Posted
2005-06-02 21:34:21 » |
|
The msot common cause of seeing no controlerls is nto having the paltform plugin properly installed.
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #2 - Posted
2005-06-03 07:10:23 » |
|
I've re-installed the driver and rewritten my code, it seems to me the driver is properly installed now. But another problem has appeared  , so I've not tested it yet. Can anybody help me with my next problem? The output I received: init: deps-jar: Compiling 1 source file to D:\School\Project Telebluppy\GUI\build\classes compile: OS name is: Windows XP DX8 plugin is supported OS name is: Windows XP DX8 plugin is supported java.lang.NoSuchMethodError: addAxis at net.java.games.input.DirectInputEnvironmentPlugin.directInputCreate(Native Method) at net.java.games.input.DirectInputEnvironmentPlugin.<init>(DirectInputEnvironmentPlugin.java:114) at idp1.Bestuuring.<init>(Bestuuring.java:22) at idp1.Main.main(Main.java:71) Exception in thread "main" Java Result: 1 debug: BUILD SUCCESSFUL (total time: 10 seconds) The error is thrown on the first line of my constructor public Bestuuring() { DirectInputEnvironmentPlugin diep = new DirectInputEnvironmentPlugin(); /* This throws an Internal Exception: * java.lang.NoSuchMethodError: addAxis * at net.java.games.input.DirectInputEnvironmentPlugin.directInputCreate(Native Method) * at net.java.games.input.DirectInputEnvironmentPlugin.<init>(DirectInputEnvironmentPlugin.java:114) */ // retrieve the available controllers net.java.games.input.Controller[] controllers = diep.getControllers(); gp = null; if (controllers.length > 0) {//error is caught in the run methode net.java.games.input.Controller c; for (int i = 0; i < controllers.length; i++) { c = controllers; if(c.getType() == net.java.games.input.Controller.Type.GAMEPAD) { // c is a gamepad gp = controllers; } } } }
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
Games published by our own members! Check 'em out!
|
|
kevglass
|
 |
«
Reply #3 - Posted
2005-06-03 07:49:27 » |
|
That would apper to be caused by the native libraries you have been out of sync with the java libraries.
Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #4 - Posted
2005-06-03 08:04:01 » |
|
That would apper to be caused by the native libraries you have been out of sync with the java libraries.
Kev
I'm a newbie so could you give me some tips on solving this?
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #5 - Posted
2005-06-03 08:38:01 » |
|
I can try To start with, where did you get your java and natives from? I've put the last versions of the jar and natives that seem to work on most platforms, here: http://www.cokeandcode.com/jinputBe warned! These are not an official release and are nowhere near up to date with the current code base. However, they are the last consistent builds that seem to work and have natives for each platform. Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #6 - Posted
2005-06-03 09:00:35 » |
|
To start with, where did you get your java and natives from?
I used the files from the NightlyBuilds. But after using your files I get the same problem. I also searched my code for any addAxis method call (for the third time) but I can not seem to find where this method is called...
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #7 - Posted
2005-06-03 09:07:16 » |
|
addAxis would be being called from inside the C code for the direct X plugin. Try out: http://www.newdawnsoftware.com/jinput/jinput.jnlpIts a webstart demo that attempts to use JInput, it works happily here. Also, could you let us know what version of java you're using (including the full version number) since some releases had significant JNI (Java Native Interface) issues. Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #8 - Posted
2005-06-03 09:16:54 » |
|
This works fine, but if I use it in my code, it (again) gives the same error my Java Version: Version 1.4.2_08 (build 1.4.2_08-b03)
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #9 - Posted
2005-06-03 09:20:45 » |
|
Hmm.. now thats interesting.. the libraries used in the webstart version are actually the same ones I've put at cokeandcode....
Ah ha, go back to your original code with the new libraries. You musn't directly instance the DirectInputEnvironementPlugin like that.
Could you repost the code that you're using after.
Kev
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #10 - Posted
2005-06-03 09:36:16 » |
|
the complete code of the thread. The code in sendAxis() might have some errors, but I'm sure my problems are not coming from there, because he can't come in that code, because I get the errorMessage "controller is null" on screen 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| package idp1;
import net.java.games.input.Axis; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; import net.java.games.input.DirectInputEnvironmentPlugin;
public class Bestuuring extends Thread { private net.java.games.input.Controller gp; public Bestuuring() { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); net.java.games.input.Controller[] controllers = ce.getControllers(); gp = null; if (controllers.length > 0) { net.java.games.input.Controller c; for (int i = 0; i < controllers.length; i++) { c = controllers[i]; if(c.getType() == net.java.games.input.Controller.Type.GAMEPAD) { gp = controllers[i]; } } } } public void run() { while (true) { if (gp == null) { errorHandler("controller is null"); } else { if (gp.poll()) { sendAxis(gp.getAxes()); errorHandler(""); } else { errorHandler("controller invalid"); } } } } private void sendAxis(Axis[] assen) { for (int i = 0; i < assen.length; i++) { float data = assen[i].getPollData(); errorHandler(assen[i].getName()); if (assen[i].getIdentifier() == Axis.Identifier.X) { if (data > 0) { sendButton(7); } if (data < 0) { sendButton(8); } } if (assen[i].getIdentifier() == Axis.Identifier.Y) { if (data < 0) { sendButton(5); } if (data > 0) { sendButton(6); } } if (assen[i].getIdentifier() == Axis.Identifier.BUTTON) { if (assen[i].getName() == "Knop 0") { sendButton(1); } if (assen[i].getName() == "Knop 1") { sendButton(2); } if (assen[i].getName() == "Knop 2") { sendButton(3); } if (assen[i].getName() == "Knop 3") { sendButton(4); } } } } private void sendButton(int button) { Main.stuur.append(String.valueOf(button)); } private void errorHandler(String message) { Main.stuur.append("e" + message); } } |
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #11 - Posted
2005-06-03 09:42:49 » |
|
Ok, now we're getting somewhere. Takeout the gamepad check for now, since your gamepad may be being reported as something else. Also you might consider just dumping out the size of the controllers array at the start (I know you've done that before, just for this version  ) Then let us know what you're getting on the console, including the junk JInput dumps out. Sorry this is taking so long  Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #12 - Posted
2005-06-03 09:50:58 » |
|
the complete console output: 1 2 3 4 5 6 7
| init: deps-jar: Compiling 1 source file to D:\School\Project Telebluppy\GUI\build\classes compile: controllers == null debug: BUILD SUCCESSFUL (total time: 32 seconds) |
and teh editted code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public Bestuuring() { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); net.java.games.input.Controller[] controllers = ce.getControllers(); gp = null; if (controllers.length == 0) { System.out.println("controllers == null"); } else { System.out.println("controllers found"); } if (controllers.length > 0) { net.java.games.input.Controller c; for (int i = 0; i < controllers.length; i++) { c = controllers[i]; gp = controllers[i]; } } } |
I should be apologizing to you that it is taking so long 
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #13 - Posted
2005-06-03 09:55:07 » |
|
Ah no, not the build console, what comes out to the console when you run it? Unless of course your ant task called "compile" is actually execute?
If so, where are your native libraries with respect to where you're running from?
Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #14 - Posted
2005-06-03 10:09:16 » |
|
I don't have much more consoles. This is the other, the debugging console: Listening on 4582 User program running User program finished my own code is in a package called idp1 the libraries are in net/java/games/input and net/java/games/util/plugin (were in .jar files, but that didn't work so I tried it extracted, with the same result. On the moent it is still in extracted state) an overview: -Source Packages ---idp1 ------Bestuuring.java ------Main.java ------<more files, witch I think don't matter> ---net.java.games.input ------<All the files> ---net.java.games.input.test ------<All the files> ---net.java.games.util.plugin ------<All the files> ---net.java.games.util.plugin.test ------<All the files>
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #15 - Posted
2005-06-03 10:21:05 » |
|
Ah, but where is the dll?
And where are you actually running from? Java must be able to find the DLL to actually use it access your controllers.
Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #16 - Posted
2005-06-03 10:35:56 » |
|
Ah, but where is the dll? as said in the JInput Introduction sticky on top of this forum, I placed the dll as following: Installation of the plugin(s): ----------------------------------- Nearly all plugins consist of two files. One of them is the native library (e.g. dxinput.dll, libjinput.so) and the other one is the java part of the plugin (any official name for that?). There are multiple ways for installing a plugin:
1) the easiest but most (system) polluting way: create a folder named 'controller' inside your ${jre.home}/lib/ext folder and copy the two files in. The project itself is located on another harddrive, but that was never a problem and I don't know why it should be a problem now...
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #17 - Posted
2005-06-03 10:53:48 » |
|
Ah, now this gets all murky  You need to have the jar and dll in the same location. So the dxinput.jar needs to be in there with the dll and the source needs to be removed from your directory. Really you should be working off the jars... What was the problem when you tried to work with the jars? Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #18 - Posted
2005-06-03 11:18:20 » |
|
the dxinput.jar is in ${jre.home}/lib/ext/controller/ together with the dll I never extracted that jar, only the jars in the applications classpath (jinput.jar and jutils.jar). The reason was to see if it would work extracted. But it did not make a difference (as you would propably have expected  )
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #19 - Posted
2005-06-03 12:30:36 » |
|
Ok, still can't work out why the plugin isn't being picked up. If you just want to get up and running, you could try setting the System Property "jinput.plugins" to the name of the plugin class you want to use before you use the default environment, 1 2 3
| System.setPropery("jinput.plugins","net.java.games.input.DirectInputEnvironmentPlugin"); ... ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); |
This forces the plugin to be picked up but in a controlled manner but its not the recommended way of doing things. This should also check if the class is actually visible to the VM. Kev
|
|
|
|
Foppie
Senior Newbie 
the Java is strong with this one!
|
 |
«
Reply #20 - Posted
2005-06-03 12:39:37 » |
|
This is it, it is not really platform independand, is it?  But that doesn't matter, I only run the program in Windows Very, very much thanks for your help Kevglass Jos Foppele
|
(\ /) (O.o) (> <) This is bunny. Copy bunny into your signature to help him on his way to world domination.
|
|
|
kevglass
|
 |
«
Reply #21 - Posted
2005-06-03 12:47:12 » |
|
No, its really not! You can of course put a check in to detect platform (System.getProperty("os.name")) and choose the right plugin dependent on that. Its all a bit mucky and plugin system should work. When you're a bit happier and sure you want to use it, its probably worth revisiting.
Kev
|
|
|
|
|