该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package com.example.mwifi;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import com.example.socket.SocketUtil;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Client extends Activity {
EditText et_message;
TextView tv_show;
PrintWriter pw=null;
BufferedReader br=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_client);
ShiLiHuaKongJian();
new Thread(new TestClient()).start();
}
public void ShiLiHuaKongJian(){
et_message=(EditText)findViewById(R.id.et_message);
et_message.setMovementMethod(ScrollingMovementMethod.getInstance());
tv_show=(TextView)findViewById(R.id.textView1);
}
Socket socket=null;
class TestClient implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
try {
System.out.println("hhhhhhhhh");
if(socket==null||socket.isClosed()){
System.out.println("kkkkk");
socket =new Socket();
socket.connect(new InetSocketAddress("192.168.1.102", 8001), 3000);
System.out.println("nhoaadddd");
System.out.println(socket.getRemoteSocketAddress().toString()+"dddddd");
getIO();
}else{
System.out.println("socket连接上了");
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void getIO() throws IOException{
pw=SocketUtil.doWriter(socket);
br=SocketUtil.getRead(socket);
}
public void doClick(View view){
String message=et_message.getText().toString();
if(pw==null){
System.out.println("pw is null");
}
pw.println(message);
pw.flush();
}
}
大神们看看哪里错了,socket连接不上,ip地址是正确的,不知道为啥错了,报空指针