2017-03-06 263 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方法在,並分離代碼的其餘部分成三個文件。之後它運行得很好。

相關問題