我想在我的班级上实施计时器计划,并且给我一个错误
“令牌上的语法错误,删除这些令牌”
public String getTemperature()抛出RemoteException, MalformedURLException,IOException,NotBoundException
public class HelloWorldService extends TimerTask {
@Override
public void run(){
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTemperature() throws RemoteException, MalformedURLException, IOException, NotBoundException {
String result = null;
try {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/RobotAutomation/webapi/robot/get");
ClientResponse response = webResource.accept("text/plain")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Application 3 \n");
System.out.println(output);
result = String.format("Output from Application 3: %s", output);
if (!output.equals(null))
System.out.println(" -------------------------TEST1----------------------------------------- ");
move.doSomething();
/*test();
test2();*/
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
}
答案 0 :(得分:0)
从您的代码中看起来getTemperature()
方法是在run()
方法中编写的。
您无法将方法放入方法中。
@Override
public void run(){
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTemperature() throws RemoteException, MalformedURLException, IOException, NotBoundException {
String result = null;
// code..
}
}
将您的getTemperature()
方法移出run()
方法,
像这样。
@Override
public void run(){
// run method logic..
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTemperature() throws RemoteException, MalformedURLException, IOException, NotBoundException {
String result = null;
// getTemperature logic..
}