2017-03-06 257 views
-1

我很新的Java和编程一般。我在下面的代码工作使用NetBeans IDE:错误:无法找到或加载主类shoutbox.ShoutBox

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“。有人知道为什么吗?

+0

你不小心把一个右括号'}'吼吼箱箱后'=新的在线留言板();'? – theKidOfArcrania

+0

我会尝试删除一个。 – Whiteknightsky

+0

这只是创造了更多的错误。如果不在那里,我不确定闭幕的位置。 – Whiteknightsky

回答

1

为什么它不跑是因为在Java(和类名)封装是大小写敏感的原因。您应该声明包装为package shoutbox

通过命名约定,你应该总是名称小写的包(即表示包应该照样你的文件夹),你总是会利用你的类名。

+0

我将它重命名为无帽,但现在我收到此错误消息: 错误:无法找到符号 String rm = new shoutbox()。shoutOutRandomMessage(message); 符号:方法shoutOutRandomMessage(字符串[]) 位置:类发言栏 – Whiteknightsky

+0

我的意思是重命名的包,而不是类的实际名称。 – theKidOfArcrania

+0

我更改了代码: – Whiteknightsky

0

我结束了创建一个完全新的文件,并放置在Main方法在,并分离代码的其余部分成三个文件。之后它运行得很好。

相关问题