2013-01-03 154 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店/主”

相关问题