访问TOMCAT上一个文件老是报错,大家伙看看。。。
程序很简单,访问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.NetworkOnMainThreadException
at 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)
相关推荐
Tomcat Using CLASSPATH:报错和启动成功无法访问情况解决方案
Tomcat 排错方案一、报错问题解:1.报错2.解决方案:二、Tomcat启动成功无法访问 一、报错问题解: 1.报错 Using CLASSPATH: /www/apache-tomcat-10.0.0-M3-src/bin/bootstrap.jar:/www/apache-tomcat-10.0.0-M3-src/bin/tomcat-juli.jar touch: cannot touch ‘/www/apache-tomcat-10.0.0-M3-src/logs/catalina.out’: No such file or directory /www/apache-tomcat
解决IDEA配置tomcat启动报错问题
主要介绍了解决IDEA配置tomcat启动报错问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
tomcat报错Service Temporarily Unavailable tomcat解决方式
从几个方面讨论tomcat报错Service Temporarily Unavailable tomcat解决方式
上传war文件大小超过Tomcat7最大文件限制报错
the request was rejected because its size (66704562) exceeds the configured maximum (52428800)
解决idea导入ssm项目启动tomcat报错404的问题
今天小编就为大家分享一篇解决idea导入ssm项目启动tomcat报错404的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


