Hi!!!!!!!!!!!!!!! I am trying to download a web page using the java.net library. My code is as follows:
package net.android.TrafficGenerator2; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class TrafficGenerator2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = new TextView(this); tv.append("Hello, Android\n"); setContentView(tv); URL u = null; try { u = new URL("http://www.msnbc.com"); } catch (MalformedURLException e) { tv.append("Error 1\n"); setContentView(tv); } URLConnection cn = null; try { cn = u.openConnection(); } catch (IOException e) { tv.append("Error 2\n"); setContentView(tv); } cn.setDoInput(true); tv.append("Content type: " + cn.getContentType() + "; Use Caches: " + cn.getUseCaches() + "; Date: " + cn.getDate() + "; Content Length: " + cn.getContentLength() + ";\n"); InputStream is = null; try { is = cn.getInputStream(); } catch (IOException e) { tv.append("Error 3a\n"); setContentView(tv); } InputStreamReader isr = null; try { isr = new InputStreamReader(is); } catch (NullPointerException e2) { tv.append("Error 3b\n"); setContentView(tv); } BufferedReader file = null; try { file = new BufferedReader(isr); } catch(NullPointerException e3) { tv.append("Error 3c\n"); setContentView(tv); } if(file == null) { tv.append("Null\n"); setContentView(tv); } else { tv.append("Not Null\n"); setContentView(tv); } } } I get output of length of -1, and Error3a, Error3b, Error3c, and Null as output. Why????????? similar code works well on a pc. Thanks............... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---