Здравствуйте. При создании android приложения, которое должно связываться с локальным javа сервером(соединение проходит в локальной сети), возникла следующая проблема. При открытии приложения, на сервер отправляется тестовое сообщение, свидетельствующее о том, что приложению на телефоне удалось подключиться к серверу на пк, а далее приложение выдает ошибку и закрывается. В чем заключается ошибка так и не удалось понять, надеюсь на вашу помощь. За ранее спасибо за помощь
]1
Код клиента на android:
1)Класс отвечающий за соединение с сервером.
public class ClientConnection implements Runnable{
public Socket socket;
public BufferedReader in;
public PrintWriter out;
private TextView t;
Date date;
DateFormat df;
String now;
public ClientConnection(TextView t){
this.t = t;
}
public void setNet() {
// TODO Auto-generated method stub
try {
socket = new Socket("192.168.1.49", 8080);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run(){
setNet();
try {
sendMessage("hello from android!");
} catch (IOException e) {
e.printStackTrace();
}
while(socket.isConnected()){
try {
now = df.format(date);
t.append(" " + now + " " + getMessage() + "\n");
} catch (IOException e) {
System.out.print("ошибка");
}
}
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void sendMessage(String message) throws IOException{
out.println(message);
out.flush();
}
public String getMessage() throws IOException{
return in.readLine();
}}
2)Главная активность
public class DialogActivity extends Activity {
Button sendButton, smileButton;
EditText inputText;
TextView dialogView;
ClientConnection cc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_dialog);
sendButton = (Button)findViewById(R.id.sendbutton);
dialogView = (TextView)findViewById(R.id.dialogview);
inputText = (EditText)findViewById(R.id.editText);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogView.append(" " + inputText.getText() + "\n");
inputText.setText("");
}
});
}
@Override
protected void onResume(){
super.onResume();
ClientConnection cc = new ClientConnection(dialogView);
Thread t = new Thread(cc);
t.start();
}}
Код сервера на локальном пк:
public class Connection extends Thread{
public Socket clientConnection;
public BufferedReader in;
public PrintWriter out;
public JTextArea chatArea;
public String date;
public Connection(Socket socket){
clientConnection = socket;
try {
in = new BufferedReader(new InputStreamReader(clientConnection.getInputStream()));
out = new PrintWriter(clientConnection.getOutputStream());
start();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void run(){
while(clientConnection.isConnected()){
try {
chatArea.append(date+"client: " + getMessage() + "\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
clientConnection.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setArea(JTextArea textArea){
this.chatArea = textArea;
}
public void setDate(String string){
this.date = string;
}
public void sendMessage(String message) throws IOException{
out.println(message);
out.flush();
}
public void sendMessageToConnection(String message, Connection conn){
conn.out.println(message);
conn.out.flush();
}
public String getMessage() throws IOException{
return in.readLine();
}}

now = df.format(date);неnullвсе переменные – ЮрийСПб Jun 11 '17 at 11:05