2013-01-03 155 views
2

the error and the class http://puu.sh/1ITnS.png爪哇 - 「錯誤:無法找到或加載主類」錯誤

當我命名類文件Main.class,java的說,它的名稱有誤,當我將其命名爲shop.Main.class它說主要的課程無法找到。誰能幫忙?

package shop; 

import java.text.DecimalFormat; 

public class Main 
{ 
    public static void main(String args[]) 
    { 
     Cart cart = new Cart(new Catalogue()); 
     printOrder(cart); 
    } 

    public static void printOrder(Cart cart) 
    { 
     DecimalFormat df = new DecimalFormat("0.00"); 
     System.out.println("Your order:"); 
     for(int itemIndex = 0; itemIndex < cart.itemsInCart.products.size(); 
      itemIndex++) 
      if (cart.itemsInCart.products.get(itemIndex).quantity != 0) 
       System.out.println(cart.itemsInCart.products.get(itemIndex).quantity 
        + " " + cart.itemsInCart.products.get(itemIndex).name 
        + " $"+ df.format(cart.itemsInCart.products.get(itemIndex).price) 
        + " = $" + df.format 
        ((cart.itemsInCart.products.get(itemIndex).quantity 
        * cart.itemsInCart.products.get(itemIndex).price))); 

     double subtotal = 0; 
     int taxPercent = 20; 
     double tax; 
     double total; 

     for(int itemIndex = 0; itemIndex < cart.itemsInCart.products.size(); 
      itemIndex++) 
      subtotal += cart.itemsInCart.products.get(itemIndex).quantity 
      * cart.itemsInCart.products.get(itemIndex).price; 
     tax = subtotal * taxPercent/100; 
     total = subtotal + tax; 


     System.out.print("Subtotal: $" + df.format(subtotal) 
      + " Tax @ " + taxPercent + "%: $" + df.format(tax) 
      + " Grand Total: $" + df.format(total)); 
    } 
} 

以下兩行之間忽略

-------------------------

編輯總結

糟糕!您的編輯無法提交,因爲:

您的帖子沒有太多的上下文來解釋代碼段;請更清楚地解釋你的情況。

取消

-------------------------

+0

Java教程可以幫助

你的例子會工作。 –

+0

顯示你的'main'代碼 – codeMan

+0

要麼刪除'包店;從'java'文件夾 –

回答

0

編譯:〜/ JAVA> javac的店/ Main.java

運行:〜/ JAVA>的java shop.Main

2

保持Main.class和嘗試java shop.Main從命令行java文件夾

4

執行下述命令:

cd .. 
java shop.Main 

您不能在您嘗試引用的包內運行java代碼。

0

你應該小心放置班正確的文件夾,如果手動編譯(包名稱等於在磁盤上的文件夾名稱)。我推薦使用IDE(Eclipse和Netbeans都是好的和免費的選擇)。如果你把Main.class在所謂的「商店」文件夾,然後從項目的根文件夾執行的「java店/主」

相關問題