public class XGetProgramGuideDirectTestControllerCmdImpl extends ControllerCommandImpl implements XGetProgramGuideDirectTestControllerCmd {
public final String CLASSNAME = this.getClass().getName();
public void performExecute() throws ECException { /* code is here*/ }
private void callUSInterface() throws ECException { /* code is here*/ }
private void callDEInterface() throws ECException { /* code is here*/ }
private void callUKInterface() throws ECException { /* code is here*/ }
public void setRequestProperties(TypedProperty req) throws ECException { /* code is here*/ }
private void displayResponse(StringBuffer testResult) { /* code is here*/ }
public static void main(String[] args) {
XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new XGetProgramGuideDirectTestControllerCmdImpl();
PGDirTestController.performExecute();
}
}
我只是尝试使用public static void main(String[] args)
将此应用程序作为 Eclipse-RAD 中的 Java 应用程序运行,但它给了我一个错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type ECException
上:
PGDirTestController.performExecute();
请放轻松,我对Java还是很陌生的。
既然你声明了:
public void performExecute() throws ECException
然后你被迫处理ECException
.
因此,当你调用它时,你应该用try-catch
包围它,或者声明你调用它的方法以throw
异常:
public static void main(String[] args) {
XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new
XGetProgramGuideDirectTestControllerCmdImpl();
try {
PGDirTestController.performExecute();
} catch(ECException e) {
e.printStackTrace();
//Handle the exception!
}
}
或
public static void main(String[] args) throws ECException {
XGetProgramGuideDirectTestControllerCmdImpl PGDirTestController = new
XGetProgramGuideDirectTestControllerCmdImpl();
PGDirTestController.performExecute();
}
首先,按照 Java 约定,变量应该以小写开头,否则会令人困惑:
XGetProgramGuideDirectTestControllerCmdImpl pGDirTestController = new XGetProgramGuideDirectTestControllerCmdImpl();
关于你的问题,未处理的异常类型意味着此方法引发一个不是运行时异常的异常,并且你没有处理它。在 Java 中,必须显式捕获不是 RuntimeException 子级的所有异常。
try {
pGDirTestController.performExecute();
} catch (final ECException e) {
// Do whatever you need to do if this exception is thrown
}
捕获部分将在抛出ECException
时执行。应在此处添加代码来处理引发此异常时要执行的操作。我强烈建议您不要将此捕获留空,因为如果抛出异常,您将永远不会知道。
如果你将使用Java,我强烈建议你买一本Java书籍/教程。这是非常基本的东西,所以你最好很好地理解这一点。祝你好运。