I made an app that controls an ScoreBoard, I worked with socketServers on my java app, and a socket on my app. The thing is that I receive data from the server, but when I'm trying to set it to a TextView the app force closes. Here's the code, I very new to android/Java programming I don't know if working with AsyncTask causes the issue.
private class SendMessage extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
client = new Socket("192.168.11.23", 4444);
printwriter = new PrintWriter(client.getOutputStream(), true);
printwriter.write(message);
printwriter.flush();
InputStream is = client.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
score = br.readLine();
Log.i("TEST", "--> " + score + " <--");
redScore.setText(score);
client.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Aucun commentaire:
Enregistrer un commentaire