2

このプログラムは、実際のオブジェクトとその重みを取得し、アルファベット順に基づいて並べ替え、次に番号順に並べ替えます

しかし、問題は、このアプリを Eclipse で実行すると (NetBeans で試したことはありません)、問題なく動作しますが、コンパイルしてターミナルで実行しようとすると、機能せず、「couldnt」というエラーが表示されることです。メインクラスを見つける」

私のJavaファイルとクラスファイルは同じフォルダーにあるので、ディレクトリは問題ではないことに注意してください

public class testMain {

public static void main(String[] args) {
    //makes a new multidimensial array
    //the first dimension holds the name of the object 
    //the second dimension holds the weight
    //the 4's in this case show the maximum space the array can hold
    String[][] objectList = new String[4][4];

    objectList[1][0] = "Teapot";
    objectList[0][1] = String.valueOf(1);

    objectList[2][0] = "Chesterfield";
    objectList[2][2] = String.valueOf(120);

    objectList[3][0] = "Laptop";
    objectList[3][3] = String.valueOf(6);

    //printing the array
    for (int i = 1; i < 3; i++) {
        for (int j = 0; j < 3;) {
            System.out.println(objectList[i][j].toString());
        }
    }
}

}

リクエストにより:私が入れたコマンドラインで、

cd /Users/username/Desktop/JavaProjects
javac ojArray.java
(After it compiled)
java ojArray.class
4

1 に答える 1

5

ターミナルで Java プログラムをコンパイル/実行するには、次の手順を実行します。

  1. プログラムがあるディレクトリに移動します ( cd「ディレクトリの変更」コマンドを使用できます)。
    • Windows でデスクトップにアクセスするには、次のようにします。cd C:\Users\YourLogin\Desktop
    • Mac では、次のようになります。cd ~/Users/YourLogin/Desktop
  2. コンパイルするには、次のように入力javac NameOfProgram.javaします。javac testMain.java
  3. 実行するには、次のように入力java NameOfProgramします。java testMain
于 2013-06-23T22:39:22.697 に答える