“不能找到主类”错误在终端,但不是在eclipse [英] "can't find main class" error in terminal but not in eclipse
问题描述
这个程序接受现实生活的对象及其权重,并基于alphebatical顺序然后数字排序
This program take real life objects and its weights and sorts it based on alphebatical order and then number-wise
但问题是,当我运行这个应用程序Eclipse(没有尝试在NetBeans),它运行正常,但是当我编译并尝试在终端中运行它不工作,并带有错误,
无法找到主类
But the problem is that when I run this app in Eclipse (haven't tried in NetBeans), it runs fine, but when I compile and try to run it in terminal, it doesn't work and comes with error, "could not find main class"
请记住我的java文件和类文件在同一个文件夹下,所以目录不是问题
Keep in mind my java file and class file are in the same folder, so the directory is not the problem
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());
}
}
}
}
根据请求:
在命令行中,
By request: In the command line I put,
cd /Users/username/Desktop/JavaProjects
javac ojArray.java
(After it compiled)
java ojArray.class
推荐答案
要在终端中编译/运行Java程序,请执行以下操作:
To compile/run a Java program in terminal, you do the following:
- 转到程序所在的目录(您可以使用
cd
更改目录命令这样做)。
- 在Windows上,要进入您的桌面,它将是:
cd C:\Users\YourLogin\Desktop
- 在Mac上,它将是:
cd〜/ Users / YourLogin / Desktop
- 在Windows上,要进入您的桌面,它将是:
- Go to the directory that your program is in (you can use the
cd
"change directory" command to do so).- On Windows, to get to your desktop, it would be:
cd C:\Users\YourLogin\Desktop
- On Mac, it would be:
cd ~/Users/YourLogin/Desktop
- On Windows, to get to your desktop, it would be:
这篇关于“不能找到主类”错误在终端,但不是在eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!