logic error

Post your NXJ projects, project ideas, etc here!

Moderators: imaqine, 99jonathan, roger

New User
Posts: 4
Joined: Wed Aug 05, 2009 7:03 pm
Location: Ireland

logic error

Postby Eoin » Sun Aug 09, 2009 12:47 pm

bellow is code snippet of my main direction code as part of my path-finding project, the code compiles, and runs on the nxt however it just exits straight away, i am wondering is it a problem with my syntax or my use of generics . if i put a call straight in the for loop it runs straight away for the duration of the length. however it wont call the if statement s at all,

any help greatly appreciated

Code: Select all

//package cleary.robot;
import java.util.Iterator;
import java.util.ArrayList;
import lejos.navigation.*;
import lejos.nxt.*;
import java.io.*;

public class DirectionTest {
   public static void main(String [] args) {
      Navigator robot = new SimpleNavigator(5.6F, 13.0F,Motor.C, Motor.B, false);
     RobotMover b = new RobotMover(robot);
     PathFindingRoute route = new PathFindingRoute();
     route.appendMove(8,0); //start
     route.appendMove(7,0); // up
     route.appendMove(6,0); // up
     route.appendMove(5,0); // up
     route.appendMove(4,0); // up
     route.appendMove(4,1); // right
     route.appendMove(3,1); // up
     route.appendMove(3,2); // right
     route.appendMove(2,2); // up
     route.appendMove(1,2); // up
     route.appendMove(1,3); // right
     route.appendMove(1,4); // up
     route.appendMove(0,4); // up
     route.appendMove(0,5); // right
    RouteToDirectionsConvertor convertor = new RouteToDirectionsConvertor(route);
    ArrayList<String> directions = new ArrayList<String>();
   directions = convertor.getDirections();

int i = 0;
   This loop will take the ArrayList directions and loop through it taking all the directions and calling there rellevant
   method from the robot mover class
   for(String s : directions)// loop Count will be for each String in the directions Arraylist
   String t = directions.get(i);
   LCD.drawString(t, 0, 4);

   if(s == "North")
            b.north(); //i.e. call north() from a RobotMover object that you have created

   else if (t == "South")
   else if (t =="East")
   else if (t =="West")


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

Postby gloomyandy » Sun Aug 09, 2009 1:12 pm

A couple of things spring out...
1. In your first test you are using a variable "s" I assume this should be "t".
2. You probably should not be using "==" to compare the strings. See:


New User
Posts: 4
Joined: Wed Aug 05, 2009 7:03 pm
Location: Ireland

Back out the java book

Postby Eoin » Sun Aug 09, 2009 1:25 pm

Cheers Andy

I d want to get the java book out again


Return to “NXJ Projects”

Who is online

Users browsing this forum: No registered users and 1 guest