Touch sensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, imaqine, 99jonathan

revivor
New User
Posts: 1
Joined: Sun Jan 08, 2012 10:01 am

Touch sensor

Postby revivor » Tue Jan 10, 2012 7:29 pm

I am trying to run this code to count how many times the touch sensor is pressed, but it throw an exception. Could you please explain what is wrong with my code?

Code: Select all



   public static void main(String[] args)
   throws Exception {
       TouchSensor touch = new TouchSensor(SensorPort.S1);
      int count = 0 ;
      while(count<10){
          if(touch.isPressed()){
            count++;
            LCD.clear();
            LCD.drawInt(count, 3, 3);
            LCD.refresh();
            while ( touch.isPressed())
                {}
             }
          }
    }

}



Code: Select all

run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: lejos.nxt.SensorPort.setPowerTypeById(II)V
   at lejos.nxt.SensorPort.setPowerTypeById(Native Method)
   at lejos.nxt.SensorPort.setPowerType(SensorPort.java:1064)
   at lejos.nxt.SensorPort.setType(SensorPort.java:973)
   at lejos.nxt.SensorPort.reset(SensorPort.java:822)
   at lejos.nxt.SensorPort.<init>(SensorPort.java:804)
   at lejos.nxt.SensorPort.<clinit>(SensorPort.java:39)
   at javaapplication4.JavaApplication4.main(JavaApplication4.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

User avatar
gloomyandy
leJOS Team Member
Posts: 4699
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Touch sensor

Postby gloomyandy » Wed Jan 11, 2012 11:38 am

Please when asking for help provide as much detail as possible, so...
1. What version of leJOS are you using.
2. Are you trying to run this code on the NXT or are you using the leJOS PC API (and so run the code on a Mac/PC).
3. What host system are you using, Windows/Mac/Linux
4. What build environment are you using, command line, Eclipse, NetBeans
5. What commands did you use when building the files
6. What errors have been produced

From a quick look it seems like you are trying to write a PC side program but are using the classes.jar file that can only be used by programs that run on the NXT...

Andy

skoehler
leJOS Team Member
Posts: 1538
Joined: Thu Oct 30, 2008 4:54 pm

Re: Touch sensor

Postby skoehler » Wed Jan 11, 2012 1:16 pm

revivor wrote:

Code: Select all

run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: lejos.nxt.SensorPort.setPowerTypeById(II)V
   at lejos.nxt.SensorPort.setPowerTypeById(Native Method)
   at lejos.nxt.SensorPort.setPowerType(SensorPort.java:1064)
   at lejos.nxt.SensorPort.setType(SensorPort.java:973)
   at lejos.nxt.SensorPort.reset(SensorPort.java:822)
   at lejos.nxt.SensorPort.<init>(SensorPort.java:804)
   at lejos.nxt.SensorPort.<clinit>(SensorPort.java:39)
   at javaapplication4.JavaApplication4.main(JavaApplication4.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


You are writing code that is supposed to run on the NXT itself. But instead of using the leJOS linker to produce a *.nxj file, you try to run the *.class files directly on the PC using an ordinary JVM (like the one from Sun/Oracle). You seem to be using a build.xml wich is not really suitable for building leJOS programs that run on the NXT.


Return to “NXJ Software”

Who is online

Users browsing this forum: Google [Bot] and 1 guest