【发布时间】:2017-10-28 19:00:23
【问题描述】:
我创建了一个类TFTPClient,它允许用户连接到服务器并能够通过类方法发出某些请求。我已经在 Android Studio 之外创建并测试了它,但是当我传输和编译我的代码时出现错误。该错误是在MainActivity.java中引起的,但不是在创建类对象时引起的,而是在调用某些方法时引起的
TFTPClient c = new TFTPClient(); //Works fine
try {
c.sendAndReceive(); //Get the error
} catch (UnknownHostException e) {
e.printStackTrace();
}
这里是 sendAndReceive 方法代码
public void sendAndReceive() throws UnknownHostException {
int sendPort;
sendPort = SERVER_RECV_PORT; //(60700)
int clientConnectionPort = -1;
InetAddress serverAddress = InetAddress.getByName("172.17.49.153");
try {
clientConnectionPort = sendRequest(serverAddress, sendPort, "all");
}
catch (IOException e) {
//System.out.println("error");
}
receive(serverAddress, clientConnectionPort);
}
【问题讨论】: