To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 373
372  |  374
Subject: 
lejos program terminating immediately
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Wed, 10 Aug 2005 15:10:31 GMT
Viewed: 
6677 times
  
Hi,

I'm trying to use leJOS to display the current value of the rotation sensor I
have hooked up to Sensor Port 1, but when I run the program, the RCX just beeps
and ends the program immediately.  Here's my code:



import josx.platform.rcx.*;

public class Rot_test
{
    public static void main (String[] args) throws Exception
    {
        Sensor.S1.setTypeAndMode (SensorConstants.SENSOR_TYPE_ROT,
SensorConstants.SENSOR_MODE_ANGLE);
        Sensor.S1.addSensorListener(new SensorListener() {
            public void stateChanged(Sensor aSource, int aOldValue, int
aNewValue){
                LCD.clear();
                Integer i = new Integer(aNewValue);
                String s = i.toString();
                TextLCD.print(s);
            }
        });
        Sensor.S1.activate();
    }
}




I have a question about leJOS that may be related to this (and I think it may
have to do with the problem I'm having).  When a leJOS program is set up, and
the program finishes executing all of the code in the main(String[] args)
method, does the program just end?

I think the problem with my code may be that I set up the listeners, but after
the program finishes reading all of the code in the method, it just exits and
never watches the rotation sensor.



Does anyone know why I'm having this problem or what it is?


Thanks,

Jason



Message has 1 Reply:
  AW: lejos program terminating immediately
 
Hi Jason, you have to loop within your main program, otherwise main() will be left. E.g. use while (true) { Thread.sleep (1000); } or, use a button listener, and exit when some button has been pressed. HTH, Jochen (...) (19 years ago, 11-Aug-05, to lugnet.robotics.rcx.java)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR