I've heard that I can use another class when I use like that. But I have 2 errors and tried to solve them for several days. Need your help guys. Thank you.
import java.io.IOException;
import java.io.InputStream;
improt java.io.OutputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
public class motor implements Runnable {
private static final int final int sizeBuf = 50;
private Socket clientSock;
private Logger logger;
private SocketAddress clientAddress;
public motor(Socket clntSock, SocketAddress clientAddress, Logger logger) {
this.clientSock = clntSock;
this.logger = logger;
this.clientAddress = clientAddress;
}
public void run() {
try {
InputStream ins = clientSock.getInputStream();
OutputStream outs = clientSock.getOutputStream();
int rcvBufSize;
byte[] rcvBuf = new byte[sizeBuf];
while ((rcvBufSize = ins.read(rcvBuf)) != -1) {
String rcvData = new String(rcvBuf, 0, rcvBufSize, "UTF-8");
if(rcvData.comparTo("MotorLock") == 0) {
Class cls = Class.forName("home/pi/project/servo/servo_close");
}
if(rcvData.comparTo("MotorOpen") == 0) {
Class cls = Class.forName("home/pi/project/servo/servo_open");
}
logger.info("Received data :" + rcvData + "(" + clientAddress + ")");
outs.write(rcvBuf, 0, rcvBufSize);
}
logger.info(clientSock.getRemoteSocketAddress() + "Closed");
} catch (IOException ex) {
logger.log(Level.WARNING, "Exception in RcvThread", ex);
} finally {
try{
clientSock.close();
System.out.println("Disconnected! Client IP :" + clientAddress);
} catch(IOException e) {}
}
}
}
And when I compile this code, I've got 2 unreported exception :
motor.java:35: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
Class cls = Class.forName("home/pi/project/servo/servo_close");
motor.java:40: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
Class cls = Class.forName("home/pi/project/servo/servo_open");