基本上,在我的大学,我们已经获得了一个Finch Robot,可以帮助我们开发Java编程技能。但是,我有一个小问题。 Uni使用Windows机器,我使用Mac,基本上我们已经预先编写了代码来测试我们的Finch Robot。当我在WIndows机器中复制并粘贴代码时,Eclipse没有给我任何错误,我可以继续测试机器人,但是当我在Mac上尝试相同的东西时,我得到30个错误!我不知道我做错了什么。
以下是代码(我已将错误粘贴在代码下方):
import java.util.Random;
import javax.swing.JOptionPane;
import edu.cmu.ri.createlab.terk.robot.finch.Finch;
public class DoesMyFinchWork
{
//This value is the time for most of the tests in milliseconds, 1000 = 1 second
//Change this value if the tests are too long or short
final private static int testtime = 5000;
//This is the Finch object
private static Finch myf = null;
//This is the starting point of the testing program
public static void main(String args[])
{
String s = "";
//'myf' is the name of our Finch object
//This will used throughout the program to control your Finch and report it's status
myf = new Finch();
do
{
//Run the menu until quit or cancel is selected
s = FinchMenu();
if (s == "Light Test") RunLightTest(s);
if (s == "Tilt Test") RunTiltTest(s);
if (s == "Tap Test") RunTapTest(s);
if (s == "Temperature Test") RunTemperatureTest(s);
if (s == "Obstacle Test") RunObstacleTest(s);
if (s == "Acceleration Test") RunAccelerationTest(s);
if (s == "Left Wheel Test") RunLeftWheelTest(s);
if (s == "Right Wheel Test") RunRightWheelTest(s);
if (s == "Buzzer Test") RunBuzzerTest(s);
if (s == "Nose Test") RunNoseTest(s);
} while (s != "Quit");
System.out.println("Exiting DoesMyFinchWork...");
myf.quit();
}
//This creates the Finch menu
private static String FinchMenu()
{
Object[] possibilities = {"Light Test", "Tilt Test","Tap Test","Temperature Test", "Obstacle Test","Acceleration Test","Left Wheel Test","Right Wheel Test","Buzzer Test","Nose Test","Quit"};
String s = (String)JOptionPane.showInputDialog(null,"Dr Swift's Splendid Finch Test\n++++++++++++++++++++++++\nChoose a test from:\n\n","Week Zero Laboratory",JOptionPane.PLAIN_MESSAGE, null,possibilities,"Light Test");
if (s == null || s.length() == 0) s = "Quit";
return(s);
}
//Run the light sensor test
//Displays the left and then the right sensor output
private static void RunLightTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.getLeftLightSensor() + " " + myf.getRightLightSensor());
}
}
//Run the Tilt Test
//Displays:
//1) Is the beak down?
//2) Is the beak up?
//3) Is the Finch level?
//4) Is the Finch upside down?
//5) Is the Finch's left wing down?
//6) Is the Finch's right wing down?
private static void RunTiltTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.isBeakDown() + " " + myf.isBeakUp() + " " + myf.isFinchLevel() + " " + myf.isFinchUpsideDown() + " " + myf.isLeftWingDown() + " " + myf.isRightWingDown());
}
}
//Run the tap test
//Displays if the Finch has been tapped
private static void RunTapTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.isTapped());
}
}
//Run the temperature test
//Displays the current temperature in degrees Celsius
private static void RunTemperatureTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.getTemperature());
}
}
//Run the obstacle sensor test
//Displays if there is an obstacle left and right of the Finch
private static void RunObstacleTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.isObstacleLeftSide() + " " + myf.isObstacleRightSide());
}
}
//Run the acceleration sensor test
//Displays is the Finch is being shaken, and then the acceleration in the X, Y and Z planes
private static void RunAccelerationTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.isShaken()+ " " + myf.getXAcceleration() + " " + myf.getYAcceleration()+ " " + myf.getZAcceleration());
}
}
//Run the left wheel test
//Move the left wheel forward and backwards
private static void RunLeftWheelTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
myf.setWheelVelocities(255,0,testtime/2);
myf.setWheelVelocities(-255,0,testtime/2);
}
//Run the right wheel test
//Move the right wheel forward and backwards
private static void RunRightWheelTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
myf.setWheelVelocities(0,255,testtime/2);
myf.setWheelVelocities(0,-255,testtime/2);
}
//Sound the buzzer for a number of different frequencies
private static void RunBuzzerTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
for(int i=0;i<=5000;i+=10)
{
myf.buzz(i,10);
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < 10)
{
//Do nothing...
}
}
}
//Flash the Finch's nose red, green and blue
//Then flash it randomly
private static void RunNoseTest(String s)
{
System.out.println("\n"+"Running: "+s+"\n");
for(int r=0;r<=255;r+=5)
{
myf.setLED(r,0,0,10);
}
for(int g=0;g<=255;g+=5)
{
myf.setLED(0,g,0,10);
}
for(int b=0;b<=255;b+=5)
{
myf.setLED(0,0,b,10);
}
Random rand = new Random();
rand.setSeed(System.currentTimeMillis());
for(int i=0;i<50;++i)
{
int r = Math.abs(rand.nextInt() % 255);
int g = Math.abs(rand.nextInt() % 255);
int b = Math.abs(rand.nextInt() % 255);
myf.setLED(r,g,b,5);
}
}
}
以下是一些错误(所有30个错误都说'Finch无法解析为某种类型'):
Description Resource Path Location Type
Finch cannot be resolved to a type DoesMyFinchWork.java /DoesMyFinchWork/src line 169 Java
Problem
Finch cannot be resolved to a type DoesMyFinchWork.java /DoesMyFinchWork/src line 165 Java
Problem
Finch cannot be resolved to a type DoesMyFinchWork.java /DoesMyFinchWork/src line 161 Java
Problem
Finch cannot be resolved to a type DoesMyFinchWork.java /DoesMyFinchWork/src line 146 Java
非常感谢您的帮助!
答案 0 :(得分:2)
看起来Windows机器已经完成了一些配置,因此它知道在哪里找到这个Finch
类,而你的Mac没有。相当肯定Windows和Mac的东西在这里是一个红色的鲱鱼:如果你去找到另一个(未配置的)Windows机器,它将无法工作。
您可能需要下载具有Finch
类的库,然后在找到它的位置配置Eclipse。获取此信息的最佳位置可能是在课堂笔记/网站上。如果那些人没有,那就问问教授。
答案 1 :(得分:0)
(编辑:哦,笨蛋。没看过确切的问题......但如果你以后遇到问题......)
尝试替换
(s ==“光测试”)
带
(s.equals(“光测试”))
等等。
'JOptionPane.showInputDialog'可能在不同平台上的不同代码中实现。要使“==”起作用,对话框必须返回相同的 String对象,如可能性参数send in中所找到的那样(也需要'interned',但我认为它确实是实习文字) 。 HTH。
答案 2 :(得分:0)
在eclipse中只需找到Finch的jar,将其复制粘贴到项目的文件夹中(希望你有一个lib文件夹),右键单击该文件Build Path&gt;添加到构建路径
那应该可以解决问题。