Project Help

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Project Help

Postby bobbym » Fri Dec 09, 2011 2:41 am

Hi, my partner and I are trying to do a project in which we just make random movements while it plays a song, can anyone help figure out why this doesn't compile? It's not important the details of what is happening with the bot I think we can fix that later, I'm just missing something obvious I think, if anyone could help that would be awesome.


import lejos.nxt.*;
import lejos.robotics.navigation.DifferentialPilot;

public class Tune
{
private DifferentialPilot bot; //field declaration for a DifferentialPilot object


//the code in the main method will not change (except for the classname)
public static void main(String[] args)
{
Tune myProgram = new Tune(); //matches classname (case-sensitive)
myProgram.run();
}//main(){






private static final short [] note = {

0,114, 294,13, 0,15, 392,13, 0,15, 370,27, 0,1, 392,13, 0,1, 440,13,
0,1, 494,13, 0,15, 392,13, 0,15, 440,13, 0,1, 494,13, 0,1, 523,13,
0,1, 659,13, 0,1, 587,13, 0,15, 392,13, 0,15, 587,13, 0,15, 392,13,
0,15, 440,13, 0,1, 392,13, 0,1, 370,13, 0,1, 392,13, 0,1, 440,13,
0,15, 330,27, 0,1, 294,13, 0,15, 392,13, 0,15, 370,27, 0,1, 392,13,
0,1, 440,13, 0,1, 494,13, 0,15, 392,13, 0,15, 440,27, 0,1, 494,13,
0,1, 523,13, 0,1, 587,13, 0,15, 392,13, 0,15, 659,13, 0,15, 392,13,
0,15, 494,13, 0,1, 440,13, 0,1, 392,13, 0,1, 370,13, 0,1, 392,56,
0,1, 294,13, 0,15, 392,13, 0,15, 370,27, 0,1, 392,13, 0,1, 440,13,
0,1, 494,13, 0,15, 392,13, 0,15, 440,13, 0,1, 494,13, 0,1, 523,13,
0,1, 659,13, 0,1, 587,13, 0,15, 392,13, 0,15, 587,13, 0,15, 392,13,
0,15, 440,13, 0,1, 392,13, 0,1, 370,13, 0,1, 392,13, 0,1, 440,13,
0,15, 330,27, 0,1, 294,13, 0,15, 392,13, 0,15, 370,27, 0,1, 392,13,
0,1, 440,13, 0,1, 494,13, 0,15, 392,13, 0,15, 440,27, 0,1, 494,13,
0,1, 523,13, 0,1, 587,13, 0,15, 392,13, 0,15, 659,13, 0,15, 392,13,
0,15, 494,13, 0,1, 440,13, 0,1, 392,13, 0,1, 370,13, 0,1, 392,56,
0,1, 370,13, 0,1, 392,13, 0,1, 440,13, 0,1, 494,13, 0,1, 440,13,
0,15, 587,27, 0,1, 554,27, 0,1, 659,27, 0,1, 440,27, 0,1, 494,13,
0,1, 554,13, 0,1, 587,27, 0,1, 494,27, 0,1, 440,27, 0,1, 392,27,
0,1, 370,27, 0,1, 330,13, 0,1, 392,13, 0,1, 370,27, 0,1, 294,27,
0,1, 277,27, 0,1, 294,27, 0,1, 330,42, 0,1, 294,13, 0,1, 330,27,
0,1, 370,27, 0,1, 392,42, 0,1, 370,13, 0,1, 392,27, 0,1, 440,27,
0,1, 494,13, 0,1, 440,13, 0,1, 392,13, 0,1, 370,13, 0,1, 330,13,
0,1, 370,13, 0,1, 392,13, 0,1, 370,13, 0,1, 330,56, 0,1, 370,13,
0,1, 392,13, 0,1, 440,13, 0,1, 494,13, 0,1, 440,13, 0,15, 587,27,
0,1, 554,27, 0,1, 659,27, 0,1, 440,27, 0,1, 494,13, 0,1, 554,13,
0,1, 587,27, 0,1, 494,27, 0,1, 440,27, 0,1, 392,27, 0,1, 370,27,
0,1, 415,27, 0,1, 440,56, 0,1, 330,27, 0,1, 392,27, 0,1, 370,27,
0,1, 294,27, 0,1, 330,56, 0,1, 330,42, 0,1, 294,13, 0,1, 330,27,
0,1, 392,27, 0,1, 370,27, 0,1, 294,27, 0,1, 330,56, 0,1, 330,56,
0,1, 392,27, 0,1, 494,27, 0,1, 440,27, 0,1, 370,27, 0,1, 392,56,
0,1, 392,42, 0,1, 370,13, 0,1, 392,27, 0,1, 494,27, 0,1, 440,27,
0,1, 370,27, 0,1, 392,56, 0,1, 392,56, 0,1, 330,27, 0,1, 392,27,
0,1, 370,27, 0,1, 294,27, 0,1, 330,56, 0,1, 330,42, 0,1, 294,13,
0,1, 330,27, 0,1, 392,27, 0,1, 370,27, 0,1, 294,27, 0,1, 330,56,
0,1, 330,56, 0,1, 392,27, 0,1, 494,27, 0,1, 440,27, 0,1, 370,27,
0,1, 392,56, 0,1, 392,42, 0,1, 370,13, 0,1, 392,27, 0,1, 494,27,
0,1, 440,13, 0,1, 494,13, 0,1, 523,13, 0,1, 659,13, 0,1, 587,27,
0,1, 392,27, 0,1, 370,56, }
;


//bot movement starts here
{
}
{ for(int i=0;i<note.length; i+=2) {
final short w = note[i+1];
final int n = note[i];
if (n != 0) Sound.playTone(n, w*10);
try { Thread.sleep(w*10); } catch (InterruptedException e) {}
}
}
public void tuny(Button button) //called when the ESCAPTE button is pressed

{


for(int i=0;i<note.length; i+=2) {
final short w = note[i+1];
final int n = note[i];
if (n != 0) Sound.playTone(n, w*10);
try { Thread.sleep(w*10); } catch (InterruptedException e) {}
}

public void run();
bot.rotate(1000);
}
}
bobbym
New User
 
Posts: 2
Joined: Fri Dec 09, 2011 2:37 am

Re: Project Help

Postby Aswin » Fri Dec 09, 2011 10:11 am

Hi,

You have declared a variable called bot, but you haven't initialized the differential pilot. Therefore you cannot call the rotate function. You should also initialize the variable bot like this:

Code: Select all
private DifferentialPilot bot= new DifferentialPilot(addSomeArgumentsHere); //field declaration and initialization for a DifferentialPilot object


Next time you run into problems you should add the messages from the compiler, this makes it easier to pinpoint a problem.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 204
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Project Help

Postby skoehler » Fri Dec 09, 2011 4:44 pm

Aswin wrote:Next time you run into problems you should add the messages from the compiler, this makes it easier to pinpoint a problem.


I would like to add like ten thousand exclamations marks to that statement!
skoehler
leJOS Team Member
 
Posts: 1430
Joined: Thu Oct 30, 2008 4:54 pm

Re: Project Help

Postby bobbym » Tue Dec 13, 2011 11:49 pm

Wow, thanks so much guys, yea sorry, if I would have been thinking I would have added the compiler error, thanks so much again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
bobbym
New User
 
Posts: 2
Joined: Fri Dec 09, 2011 2:37 am


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff