有两个类:主类(Corina.java)和我有问题的类(Functions.java)。在不太复杂的情况下,Corina.java在Functions.java中调用了一个方法,该方法检查boolean是true还是false,并在此基础上请求身份验证,此时代码非常公正,尽管我使用的是phidgets阅读器,并复制了其中一部分示例。但是,在JCreator中我得到了以下错误:
--------------------Configuration: Corina - JDK version 1.7.0_45 <Default> - <Default>--------------------
C:\Users\alexis.JKLSEMICOLON\Documents\JCreator LE\MyProjects\Corina\src\Functions.java:23: error: unreported exception Exception; must be caught or declared to be thrown
authenticateContinue();
^一级代码:
public class Corina {
public static void main(String[] args) {
Functions funtion = new Functions();
funtion.authenticateStart();
}
}二级代码:
import com.phidgets.*;
import com.phidgets.event.*;
public class Functions {
public void authenticateStart() {
boolean authStatus = false;
System.out.println("The authentication status is currently: " + authStatus + ".");
if (authStatus) {
System.out.println("The applications is unlocked. Please wait.");
// applicationStart();
} else {
System.out.println("Please authenticate now by swiping one of the RFID tags allowed to unlock the program.");
authenticateContinue();
}
}
public void authenticateContinue() throws Exception {
RFIDPhidget rfid;
System.out.println(Phidget.getLibraryVersion());
rfid = new RFIDPhidget();
rfid.addAttachListener(new AttachListener() {
public void attached(AttachEvent ae) {
try {
((RFIDPhidget) ae.getSource()).setAntennaOn(true);
((RFIDPhidget) ae.getSource()).setLEDOn(true);
} catch (PhidgetException ex) {
}
System.out.println("attachment of " + ae);
}
});
rfid.addDetachListener(new DetachListener() {
public void detached(DetachEvent ae) {
System.out.println("detachment of " + ae);
}
});
rfid.addErrorListener(new ErrorListener() {
public void error(ErrorEvent ee) {
System.out.println("error event for " + ee);
}
});
rfid.addTagGainListener(new TagGainListener() {
public void tagGained(TagGainEvent oe) {
System.out.println(oe);
}
});
rfid.addTagLossListener(new TagLossListener() {
public void tagLost(TagLossEvent oe) {
System.out.println(oe);
}
});
rfid.addOutputChangeListener(new OutputChangeListener() {
public void outputChanged(OutputChangeEvent oe) {
System.out.println(oe);
}
});
rfid.openAny();
System.out.println("waiting for RFID attachment...");
rfid.waitForAttachment(1000);
System.out.println("Serial: " + rfid.getSerialNumber());
System.out.println("Outputs: " + rfid.getOutputCount());
System.out.println("Outputting events. Input to stop.");
System.in.read();
System.out.print("closing...");
rfid.close();
rfid = null;
System.out.println(" ok");
if (false) {
System.out.println("wait for finalization...");
System.gc();
}
}
}任何帮助都将不胜感激。理想情况下,我希望将标记保存到字符串中,因此,如果您对此有所了解的话,请尽一切努力。
发布于 2013-11-18 04:29:10
您的问题是authenticateStart调用了authenticateContinue(),但是您已经将authenticateContinue标记为能够抛出Exception。这意味着当抛出异常时,authenticateStart需要能够处理该异常。你有几个选择。
authenticateContinue的调用放在try块中,并在其下面的catch块中处理异常。authenticateContinue,使其不会抛出已检查的异常。authenticateStart标记为能够抛出Exception。这将把问题推到main中,您在那里调用authenticateStart。不管你做什么,你都得设法处理这个例外。Java异常处理的全部要点是,您不能只是不处理检查过的异常--您必须以某种方式处理它们。
https://stackoverflow.com/questions/20039991
复制相似问题