1

基本的に、私の大学では、Java プログラミングのスキルを開発するのに役立つ Finch ロボットが与えられています。ただし、少し問題があります。Uni は Windows マシンを使用し、私は Mac を使用しています。基本的に、Finch ロボットをテストするための事前に作成されたコードが提供されています。コードをコピーして 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

助けてくれてありがとう!

4

3 に答える 3

2

FinchWindows マシンでは、このクラスを見つける場所を認識できるように、既にいくつかの構成が行われているようですが、Mac では認識されません。ここでは、Windows 対 Mac の問題がニシンであることはほぼ確実です。別の (構成されていない) Windows マシンを見つけた場合、それは機能しません。

おそらく、Finchクラスを含むライブラリをダウンロードしてから、それを見つける場所で Eclipse を構成する必要があります。この情報を入手するのに最適な場所は、おそらく授業ノート/ウェブサイトでしょう。持っていない人は、教授に聞いてみてください。

于 2012-10-04T16:44:53.137 に答える
0

(編集:ああ、くそ。正確な質問を読んでいませんでしたが、後で問題が発生した場合は...)

交換してみる

(s == "ライト テスト")

(s.equals("ライト テスト"))

等々。

おそらく「JOptionPane.showInputDialog」は、異なるプラットフォームの異なるコードで実装されています。「==」が機能するには、ダイアログは送信される可能性パラメーターにあるのと同じ文字列オブジェクトを返す必要があります (これも「インターン」する必要がありますが、インターン リテラルを行うと思います)。HTH。

于 2012-10-04T16:47:25.073 に答える
0

Eclipse では、Finch の jar を見つけて、プロジェクトのフォルダー (できれば lib フォルダーがあることを願っています) にコピーして貼り付け、そのファイルを右クリックし、[ビルド パス] > [ビルド パスに追加] を選択します。

これで問題は解決するはずです。

于 2012-10-04T17:36:10.027 に答える