【发布时间】:2012-11-02 03:53:57
【问题描述】:
我在运行以下代码时遇到问题,上面写着Error: Could not find or load main class,但我显然在代码中有一个主...
package abc;
import java.io.IOException;
import javax.swing.JOptionPane;
// As its name implies, this is what is driving the program, asking for input, giving output, etc.
public class driver
{
@SuppressWarnings("unused")
public static void main(String args[]) throws IOException // a main that throws an exception... hmmm... yes it's odd, but apparently not illegal
{
....}
private static void processTransaction(String trans, Customer[] customers) throws IOException // this is the function that processes the given transaction
{
...
}
// An object representing a person who may have one or more bank accounts
class Customer
{
...
}
class BankAccount
{
...
}
class CheckingAccount extends BankAccount // extends BankAccount with added functionality
{
...
}
class SavingsAccount extends BankAccount // extends BankAccount with added functionality
{
...
}
【问题讨论】:
-
你的 sscce 不是很短 :)
-
我将其留在评论中而不是答案中,因为这是疯狂的猜测,但也许您的编译器正在寻找
main类而不是main方法,或者可能是它寻找不会抛出IOException的main -
你不能有一个名为
default的包,它不会编译。 -
@SamIam.. 我敢打赌,您没有将其发布为答案,从而为自己节省了很多声誉。
-
@user133466.. 你的编译单元的名称是什么?是
driver吗? P.S,请以大写字母开头的班级命名。