我正在編寫一個java程序,我必須創建一個類(InvoiceTest),它將包含主類和第二類(發票)。當我運行主InvoiceTest類時,它應該在Invoice類中顯示消息。我不斷收到錯誤將主類連接到其他類
Exception in thread "main" java.lang.ExceptionInInitializerError
at InvoiceTest.main(InvoiceTest.java:4)
Caused by: java.lang.RuntimeException: Uncompilable source code - constructor Invoice() is already defined in class Invoice
at Invoice.<clinit>(Invoice.java:20)
... 1 more
我不知道該怎麼做,請讓我知道我在做什麼錯誤以及如何解決它的任何建議。謝謝
public class InvoiceTest{
public static void main(String [] args) {
Invoice invoiceObject = new Invoice();
invoiceObject.simpleMessage();
}
}
// This is the second class. I am using NetBeans so each class is in its own window.
public class Invoice {
public void simpleMessage() {
System.out.println("This is another class");
}
}
'構造發票? – nachokk
這是你的完整代碼? – nachokk
是的,現在我剛開始,所以我會加入。解碼是什麼意思? – user2005617