Hi! I'm having weird problems with a socket connection in an AsyncTask:
public class diagnosis extends Activity { TextView tv; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.diagnosis_test_gui); //textview erzeugen tv = (TextView) findViewById(R.id.dtg_tv); tv.setMovementMethod(ScrollingMovementMethod.getInstance()); } private class conmng extends AsyncTask<String, Void, Integer> { PrintWriter pw; OutputStream os; BufferedReader br; @Override protected Integer doInBackground(String... params) { Socket cs = null; try { cs.setSoTimeout(500); } catch (SocketException e) { tv.append("Socket Timeout"); e.printStackTrace(); } tv.append("trying to open socket\n"); try { tv.append("before socket\n"); cs = new Socket("10.0.0.4", 23); tv.append("after socket"); os = cs.getOutputStream(); pw = new PrintWriter(os, false); br = new BufferedReader(new InputStreamReader(cs.getInputStream())); } catch (UnknownHostException uh) { uh.printStackTrace(); tv.append("unknown host"); } catch (IOException io) { tv.append("IO Exception"); io.printStackTrace(); } catch (SecurityException se) { tv.append("Security Exception"); } //do something.... return 1; } @Override protected void onPostExecute(Integer result) { // TODO Auto-generated method stub tv.append("im Post Execute"); super.onPostExecute(result); } } ->If I try to set the timeout of the Socket -> null Pointer Exception ->If I try to connect to an existing address, I get the message "tv.append("after socket");" but just a second after that I get "08-13 20:44:05.657: ERROR/AndroidRuntime(304): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views." ->If I try to connect to an address that is not existing(which is exactly the situation I want to simulate) I wont get any exception like "unknown host" or anything it just hangs and hangs and hangs withour any error or something till it kills my router with its trying(DDos anyone?) :D The whole thing worked just fine in native java and I would greatly appreciate any help!!!!! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en