Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  getControllers() gives an empty array  (Read 3255 times)
0 Members and 1 Guest are viewing this topic.
Offline 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:
Quote
/*
* 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.
Offline Jeff

JGO Coder




Got any cats?


« 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.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline 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 Huh, so I've not tested it yet. Can anybody help me with my next problem?

The output I received:
Quote
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
Quote
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!
Legends of Yore - The Casual Retro Roguelike
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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

Offline 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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2005-06-03 08:38:01 »

I  can try Wink

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/jinput

Be 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


Offline 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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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.jnlp

Its 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

Offline 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 Huh

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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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();
        // retrieve the available controllers  
       net.java.games.input.Controller[] controllers = ce.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[i];
                if(c.getType() ==  net.java.games.input.Controller.Type.GAMEPAD) { // c is a 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());//for debugging only!
           if (assen[i].getIdentifier() == Axis.Identifier.X) {
                if (data > 0) { //arrow right
                   sendButton(7);
                }
                if (data < 0) { //arrow left
                   sendButton(8);
                }
            }
            if (assen[i].getIdentifier() == Axis.Identifier.Y) {
                if (data < 0) { //arrow up
                   sendButton(5);
                }
                if (data > 0) { //arrow down
                   sendButton(6);
                }
                /* alternative buttons for up and down
                if ((assen[i].getName() == "Knop 5") || (assen[i].getName() == "Knop 7")) {//up, R1 and R2 buttons
                    sendButton(5);
                }
                if ((assen[i].getName() == "Knop 4") || (assen[i].getName() == "Knop 6")) {//down, L1 and L2 buttons
                    sendButton(6);
                }
                */

            }
            if (assen[i].getIdentifier() == Axis.Identifier.BUTTON) {
                if (assen[i].getName() == "Knop 0") {//button 1
                   sendButton(1);
                }
                if (assen[i].getName() == "Knop 1") {//button 2
                   sendButton(2);
                }
                if (assen[i].getName() == "Knop 2") {//button 3
                   sendButton(3);
                }
                if (assen[i].getName() == "Knop 3") {//button 4
                   sendButton(4);
                }
            }
        }
    }
   
    private void sendButton(int button) {
        Main.stuur.append(String.valueOf(button)); // not "k" + 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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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 Wink)

Then let us know what you're getting on the console, including the junk JInput dumps out.

Sorry this is taking so long Sad

Kev

Offline 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();
        // retrieve the available controllers  
       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) {//error is caught in the run methode
           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) { // c is a gamepad
                   gp = controllers[i];
                //}
           }
        }
    }


I should be apologizing to you that it is taking so long Wink

(\ /)
(O.o)
(> <)
This is bunny.
Copy bunny into your signature to help him on his way to world domination.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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

Offline 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:
Quote
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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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

Offline 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:
Quote
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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #17 - Posted 2005-06-03 10:53:48 »

Ah, now this gets all murky Smiley

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

Offline 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 Wink)

(\ /)
(O.o)
(> <)
This is bunny.
Copy bunny into your signature to help him on his way to world domination.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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

Offline 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? Wink

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.
Online kevglass

JGO Kernel


Medals: 172
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (43 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!