Java 错误:无法找到或加载主类shoutbox.shoutbox

Java 错误:无法找到或加载主类shoutbox.shoutbox,java,arrays,string,class,compiler-errors,Java,Arrays,String,Class,Compiler Errors,我对Java和一般编程非常陌生。我正在使用NetBeans IDE编写以下代码: package ShoutBox; import java.util.Scanner; public class ShoutBox { public static void main(String args[]){ ShoutBox shoutbox = new ShoutBox(); } Scanner input = new Scanner(System.in); i

我对Java和一般编程非常陌生。我正在使用NetBeans IDE编写以下代码:

package ShoutBox;
import java.util.Scanner;


public class ShoutBox {
    public static void main(String args[]){
    ShoutBox shoutbox = new ShoutBox();
    }
    Scanner input = new Scanner(System.in);
    int selection = 0;


    public void message() {

        String message[] = new String[10]; // declare array

        message[0] = "01: Free Will Exists.";
        message[1] = "02: Since Free Will Exists, Evil Exists.";
        message[2] = "03: Evil, being evil, will not stop on its own.";
        message[3] = "04: For Good to continue to exist, Evil must be stopped.";
        message[4] = "05: It is good that Good exists.";
        message[5] = "06: It is good to stop evil.";
        message[6] = "07: Good persons will attempt to stop evil or else they are not good.";
        message[7] = "08: Evil brings war.";
        message[8] = "09: Since evil brings war and will not stop, good must fight and win those wars.";
        message[9] = "10: Just war exists.";

        System.out.println();

        String cm = new ShoutBox().shoutOutCannedMessage(message); //call to shoutOutCannedMessage
        String rm = new ShoutBox().shoutOutRandomMessage(message);
        System.out.println("Philosophy: ");
        System.out.println(cm);
        System.out.println("Your Random Message: ");
        System.out.println(rm);


    }

    public String shoutOutCannedMessage(String[] message)
    { 
    ShoutBox shoutbox = new ShoutBox();
        for (String element : message)
        {
            System.out.println(element); //print out messages
        }

        System.out.print("Select a message: ");
        System.out.println();

        selection = input.nextInt();

        String cannedMessage = message[selection];

        return cannedMessage;


    }


}

它构建和加载很好,但不会运行,并给出错误代码:“错误:无法找到或加载主类shoutbox.shoutbox。”有人知道原因吗?

它不运行的原因是java中的包(和类名)区分大小写。您应该将包声明为
package shoutbox


通过命名约定,您应该始终以小写字母命名包(表示包的文件夹也应该这样做),并且始终将类名大写。

我最终创建了一个全新的文件,并将主方法放在其中,并将其余代码分为三个文件。从那以后一切都很好

您是否不小心在
ShoutBox=new ShoutBox()之后放了一个紧括号
}
?我将尝试删除一个。这会导致更多错误。如果没有,我不确定关闭}应该放在哪里。您的
扫描仪输入
行应该放在主方法内部吗?现在它不在任何方法中。我将Scanner输入放在main方法中,如下所示:public类shoutbox{public static void main(String args[]){shoutbox shoutbox=new shoutbox();Scanner input=new Scanner(System.in);int selection=0;}但现在收到一条消息“变量shoutbox未使用”。对于“输入”和“选择”也是如此。我将其重命名为不带大写,但现在收到以下错误消息:错误:找不到符号字符串rm=new shoutbox()。shoutOutRandomMessage(消息);符号:方法shoutOutRandomMessage(字符串[])位置:class shoutboxI旨在重命名包,而不是类的实际名称。