初学安卓网络这一块 ,很基础,大家别见笑程序很简单,访问TOMCAT 下面的一个TXT文件   在浏览器上面已经成功访问到了  但程序一直报错退出
public class Activity01 extends Activity {
private TextView httpText;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.http1);
httpText = (TextView)findViewById(R.id.httpText);
String httpUrl = "http://192.168.5.103:8080/jsp/http.txt";
String data = "";
URL url =null;
try{
url = new URL(httpUrl);
System.out.println(url+"");
}
catch(MalformedURLException e){
Log.v("Activity01","MalformedURLException");
}
if(url!=null){
try{
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
InputStreamReader in = new InputStreamReader(urlConn.getInputStream());
BufferedReader br = new BufferedReader(in);
String inputLine = null;
while((inputLine=br.readLine())!=null){
data+=inputLine + "\n";
}
in.close();
urlConn.disconnect();
httpText.setText(data);
}
catch(IOException e){
Log.v("Activity01","IOException");
}
}
else{httpText.setText("内容为空");}
}}
权限是:<uses-permission android:name="android.permission.INTERNET"></uses-permission>错误LOG是 :java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test_http1/com.example.test_http1.Activity01}: android.os.NetworkOnMainThreadExceptionat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)TomcatURLAndroid浏览器