#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0

    Need urgent help


    Connecting to Finch...this may take a few seconds...
    Enter New Command
    S F 10 1000
    Exception in thread "main" java.lang.NullPointerException
    at Code.simpleOutput.FinchWorking.moveForward(FinchWorking.java:27)
    at Code.simpleOutput.Main.forward(Main.java:157)
    at Code.simpleOutput.Main.Single(Main.java:61)
    at Code.simpleOutput.Main.main(Main.java:26)


    i keep on getting this error.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    What's on line 27 of FinchWorking?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0
    myFinch.setWheelVelocities(speed, speed, time);
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Originally Posted by lankan12
    myFinch.setWheelVelocities(speed, speed, time);
    From the error, it looks like myFinch is null
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0
    Originally Posted by bullet
    From the error, it looks like myFinch is null
    can i send you my working files? because i actually dont know where i went rong and what to add now.,

    i cant send a pm to you is not letting me i will email you ?
  10. #6
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Originally Posted by lankan12
    can i send you my working files? because i actually dont know where i went rong and what to add now.,

    i cant send a pm to you is not letting me i will email you ?
    can you post the code here?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0
    Originally Posted by bullet
    can you post the code here?
    Main.java
    Code:
    package Code.simpleOutput;
    
    
    
    import java.util.Scanner;
    
    public class Main {
    	
    	private static String commandslog="";
    	private static long MeanTime = 0;
    	private static long MeanSpeed = 0;
    	private static int No_of_commands = 0;
    	
    	public static void main(String[] args) 
    	{
    		String input="";
    		Scanner in = new Scanner(System.in);
    		Boolean end = false;
    		FinchWorking.start();
    		while(!end)
    		{
    			System.out.println("Enter New Command");
    			input = in.nextLine();
    			if(input.charAt(0)=='S'||input.charAt(0)=='s')
    			{
    				Single(input);
    			}
    			else if(input.charAt(0)=='D'||input.charAt(0)=='d')
    			{
    				Double(input);
    			}
    			else if(input.charAt(0)=='T'||input.charAt(0)=='t')
    			{
    				Triple(input);
    			}
    			else if(input.charAt(0)=='Q'||input.charAt(0)=='q')
    			{
    				end = true;
    				FinchWorking.Stop();
    				System.out.println("Program End . . .");
    				System.out.println("Mean Speed = "+ (MeanSpeed/No_of_commands) );
    				System.out.println("Mean Time = "+ (MeanTime/No_of_commands) );
    				System.out.println("No of Commands = "+ (No_of_commands) );
    				commandslog += "Mean Speed = "+ (MeanSpeed/No_of_commands)+"\r\n";
    				commandslog += "Mean Time = "+ (MeanTime/No_of_commands)+"\r\n";
    				commandslog += "No of Commands = "+ (No_of_commands) ;
    				output.output(commandslog);
    			}
    			else
    			{
    				System.out.println("Invalid Command: "+input);
    				commandslog+="Invalid Command: "+input+"\r\n";
    			}
    		}
    	}
    	
    	public static void Single(String input)
    	{
    		if(input.charAt(2)=='F'||input.charAt(0)=='f')
    		{
    			forward(input);
    		}
    		else if(input.charAt(2)=='B'||input.charAt(0)=='b')
    		{
    			backward(input);
    		}
    		else if(input.charAt(2)=='L'||input.charAt(0)=='l')
    		{
    			left(input);
    		}
    		else if(input.charAt(2)=='R'||input.charAt(0)=='r')
    		{
    			right(input);
    		}
    		else
    		{
    			System.out.println("Invalid Command: "+input);
    			commandslog+="Invalid Command: "+input+"\r\n";
    		}
    	}
    	
    	public static void Double(String input)
    	{
    		String[] cmnd = input.split(",");
    		
    		if(cmnd[0].charAt(2)=='F'||cmnd[0].charAt(0)=='f')
    		{
    			forward(cmnd[0]);
    			Single("S "+cmnd[1]);
    		}
    		else if(cmnd[0].charAt(2)=='B'||cmnd[0].charAt(0)=='b')
    		{
    			backward(cmnd[0]);
    			Single("S "+cmnd[1]);
    		}
    		else if(cmnd[0].charAt(2)=='L'||cmnd[0].charAt(0)=='l')
    		{
    			left(cmnd[0]);
    			Single("S "+cmnd[1]);
    		}
    		else if(cmnd[0].charAt(2)=='R'||cmnd[0].charAt(0)=='r')
    		{
    			right(cmnd[0]);
    			Single("S "+cmnd[1]);
    		}
    		else
    		{
    			System.out.println("Invalid Command: "+input);
    			commandslog+="Invalid Command: "+input+"\r\n";
    		}
    	}
    	
    	public static void Triple(String input)
    	{
    		String[] cmnd = input.split(",");
    		
    		if(cmnd[0].charAt(2)=='F'||cmnd[0].charAt(0)=='f')
    		{
    			forward(cmnd[0]);
    			Single("S "+cmnd[1]);
    			Single("S "+cmnd[2]);
    		}
    		else if(cmnd[0].charAt(2)=='B'||cmnd[0].charAt(0)=='b')
    		{
    			backward(cmnd[0]);
    			Single("S "+cmnd[1]);
    			Single("S "+cmnd[2]);
    		}
    		else if(cmnd[0].charAt(2)=='L'||cmnd[0].charAt(0)=='l')
    		{
    			left(cmnd[0]);
    			Single("S "+cmnd[1]);
    			Single("S "+cmnd[2]);
    		}
    		else if(cmnd[0].charAt(2)=='R'||cmnd[0].charAt(0)=='r')
    		{
    			right(cmnd[0]);
    			Single("S "+cmnd[1]);
    			Single("S "+cmnd[2]);
    		}
    		else
    		{
    			System.out.println("Invalid Command: "+input);
    			commandslog+="Invalid Command: "+input+"\r\n";
    		}
    	}
    	
    	public static void forward(String input)
    	{
    		String[] bc = input.split(" ");
    		int speed = Integer.parseInt(bc[2]);
    		int time = Integer.parseInt(bc[3]);
    		
    		MeanSpeed += speed;
    		MeanTime += time;
    		No_of_commands++;
    		FinchWorking.moveForward(speed, time);
    		System.out.println("Success in forward with speed:"+speed+" and with time: "+time);
    		commandslog+="Success in forward with speed:"+speed+" and with time: "+time+"\r\n";
    	}
    	
    	public static void backward(String input)
    	{
    		String[] bc = input.split(" ");
    		int speed = Integer.parseInt(bc[2]);
    		int time = Integer.parseInt(bc[3]);
    		
    		MeanSpeed += speed;
    		MeanTime += time;
    		No_of_commands++;
    		
    		FinchWorking.moveBackward(speed, time);
    		System.out.println("Success in backward with speed:"+speed+" and with time: "+time);
    		commandslog+="Success in backward with speed:"+speed+" and with time: "+time+"\r\n";
    	}
    	
    	public static void left(String input)
    	{
    		String[] bc = input.split(" ");
    		int rightspeed = Integer.parseInt(bc[2]);
    		int time = Integer.parseInt(bc[3]);
    
    		MeanSpeed += rightspeed;
    		MeanTime += time;
    		No_of_commands++;
    		
    		FinchWorking.turnLeft(rightspeed, time);
    		System.out.println("Success in left with speed:"+rightspeed+" and with time: "+time);
    		commandslog+="Success in left with speed:"+rightspeed+" and with time: "+time+"\r\n";
    	}
    	
    	public static void right(String input)
    	{
    		String[] bc = input.split(" ");
    		int leftspeed = Integer.parseInt(bc[2]);
    		int time = Integer.parseInt(bc[3]);
    
    		MeanSpeed += leftspeed;
    		MeanTime += time;
    		No_of_commands++;
    		
    		FinchWorking.turnRight(leftspeed, time);
    		System.out.println("Success in right with speed:"+leftspeed+" and with time: "+time);
    		commandslog+="Success in right with speed:"+leftspeed+" and with time: "+time+"\r\n";
    	}

    FinchWorking.Java
    Code:
    package Code.simpleOutput;
    
    
    
    import edu.cmu.ri.createlab.terk.robot.finch.Finch;
    
    
    
    public class FinchWorking
    {
    	private static Finch myFinch;
    	
    	public static void start()
    	{
    		Finch myFinch = new Finch();
    		myFinch.setLED(255,0,0);
    		myFinch.saySomething("Start");
    		myFinch.sleep(1500);
    		{
    				}
    	
    	}
    	
    	//both speeds should be same to go forward
    	public static void moveForward(int speed,int time)
    	{
    			myFinch.setWheelVelocities(speed, speed, time);
    	}
    	
    	//both speeds should be same to go backward
    	public static void moveBackward(int speed , int time)
    	{	
    		myFinch.setWheelVelocities(-speed, -speed, time);
    		
    	}
    	
    	
    	//left wheel's speed is zero as to move left and i always be zero in this operation
    	public static void turnLeft(int rightspeed,int time)
    	{	
    			myFinch.setWheelVelocities(0, rightspeed, time);
    	}
    	
    	//right wheel's speed is zero as to move right and i always be zero in this operation
    	public static void turnRight(int leftspeed,int time)
    	{	
    			myFinch.setWheelVelocities(leftspeed, 0, time);
    	}
    	
    	public static void Stop()
    	{	
    		myFinch.quit();
    	}
    	
    }
  14. #8
  15. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    I believe this is your problem. Note that in start, you declare myFinch.

    Code:
    private static Finch myFinch;
    	
    	public static void start()
    	{
    		Finch myFinch = new Finch();
    		myFinch.setLED(255,0,0);
    		myFinch.saySomething("Start");
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0
    Originally Posted by bullet
    I believe this is your problem. Note that in start, you declare myFinch.

    Code:
    private static Finch myFinch;
    	
    	public static void start()
    	{
    		Finch myFinch = new Finch();
    		myFinch.setLED(255,0,0);
    		myFinch.saySomething("Start");

    But i need it carry on for the other results aswell doea that mean i need to declare a new finch for every public static void?
  18. #10
  19. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    No, what I mean is, since you are declaring myFinch in start, it does not affect the class variable. The new declaration will hide it.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    6
    Rep Power
    0
    Originally Posted by bullet
    No, what I mean is, since you are declaring myFinch in start, it does not affect the class variable. The new declaration will hide it.
    so theres no way i can get it to work?
  22. #12
  23. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Originally Posted by lankan12
    so theres no way i can get it to work?
    Just take out the new declaration in start
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Need some help too


    ]   &MF.J*R)/j6϶gR"f!*
    sV# j,K𲳬o_bk$ɶ?CVflj%nrqe}Qm%;!%2=Ձ22>\QDIPm Gߣ֯bGׇ{j۾Om^zx({a*:`&*!,gF`$X
    Fˤ$^WE]*!(Fy]\2m~p@o`k;r<J
    *v#9ѶlBfcГ`d8Sm4yE@Ok(04$9jX!Dc'YkZ8^h B>/?Ʒī; $͞zD1* -}8D4>ml@u HP"a#G_GVH@tPw
    B1@L^wgBѡr}+x=I!vD4U?K+&o&W榀 IտQcU+@|>1ӑ 5vYFhA. 11Bf$lmJǓ&jenda|أ}Dk-
    R7n)a+_>*3#0vlC&*(
    kٷZv(hrEt$g5CALaTI{]甑&J諭uW3iavJ+׌# ]O7\As
    :n XczG—"TF*4DzT';ܧPCeߟZ}DPJC]iՏ%\{4f&%f8M 5P` p9-ѡyIu֥pU]D;t)1B*Cty@=k*ud ̳8 XLjh&\Wu2GJ!Z 8

    You guys have any idea what this is?

IMN logo majestic logo threadwatch logo seochat tools logo