Android java.io.ioexception尝试在封闭流上读取
我是android世界的新手。我试图理解客户端和服务器的连接,所以,我写了一个程序,但它向我显示java.io.ioexception试图在封闭流上读取,并且在我的日志中,当我打印转换后的响应时,它向我显示整个html页面。这是我的密码Android java.io.ioexception尝试在封闭流上读取,android,Android,我是android世界的新手。我试图理解客户端和服务器的连接,所以,我写了一个程序,但它向我显示java.io.ioexception试图在封闭流上读取,并且在我的日志中,当我打印转换后的响应时,它向我显示整个html页面。这是我的密码 private class getDataFromDatabse extends AsyncTask<String, String, String> { boolean switchintent=false; Str
private class getDataFromDatabse extends AsyncTask<String, String, String> {
boolean switchintent=false;
String busStopNme;
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(WelcomeActivity.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
// TODO Auto-generated method stub
HttpClient httpclient = new DefaultHttpClient();
System.out.println("IP is " + IP);
HttpPost httppost = new HttpPost("http://" + IP + "/connection.php");
/*List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("BusStopName","thakur_complex"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));*/
System.out.println(httppost);
Log.e("welocmeActivity", "HTTPPost is " + httppost.getURI());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
System.out.println("top of convert string");
String tempValue = convertString(is);
System.out.println(tempValue);
if (convertString(is) == "succeed") {
busStopNme = "Thakur Complex";
switchintent=true;
}
System.out.println(is.toString());
System.out.println("bottom of convert string");
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception" +e);
e.printStackTrace();
}
return busStopNme;
}
private String convertString(InputStream is) {
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"), 8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
reader.close();
busStopNme = sb.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return busStopNme;
}
私有类GetDataFromDatabase扩展异步任务{
布尔值switchintent=false;
字符串bustopnme;
私人对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(WelcomeActivity.this);
setMessage(“获取数据…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
试一试{
//TODO自动生成的方法存根
HttpClient HttpClient=新的DefaultHttpClient();
System.out.println(“IP为”+IP);
HttpPost-HttpPost=newhttppost(“http://“+IP+”/connection.php”);
/*List nameValuePairs=新的ArrayList(1);
添加(新的BasicNameValuePair(“BusStopName”、“thakur_复合体”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs))*/
系统输出打印项次(httppost);
Log.e(“welocmeActivity”,“HTTPPost是”+HTTPPost.getURI());
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
is=entity.getContent();
System.out.println(“转换字符串的顶部”);
字符串tempValue=转换字符串(is);
System.out.println(tempValue);
如果(转换字符串(is)=“成功”){
bustopnme=“Thakur综合体”;
switchintent=true;
}
System.out.println(is.toString());
System.out.println(“转换字符串的底部”);
}捕获(例外e){
//TODO:处理异常
系统输出打印项次(“例外”+e);
e、 printStackTrace();
}
返回巴士站;
}
私有字符串转换字符串(InputStream为){
缓冲读取器;
试一试{
reader=新的BufferedReader(新的InputStreamReader(is,“iso-8859-1”),8);
sb=新的StringBuilder();
sb.append(reader.readLine()+“\n”);
字符串行=“0”;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
reader.close();
busStopNme=sb.toString();
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回巴士站;
}
我的日志文件如下所示
1-25 17:55:02.473: I/System.out(383): IP is **********
11-25 17:55:02.473: I/System.out(383): org.apache.http.client.methods.HttpPost@4a32c610
11-25 17:55:02.473: E/welocmeActivity(383): HTTPPost is http://**********/connection.php
11-25 17:55:02.763: I/System.out(383): above tts in init
11-25 17:55:02.763: I/TTS received:(383): Welcome to Audio Bus , Please wait we are retriving information
11-25 17:55:02.773: I/System.out(383): below tts in init
11-25 17:55:04.373: I/System.out(383): top of convert string
11-25 17:55:04.383: I/System.out(383): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
11-25 17:55:04.383: I/System.out(383): <html><head>
11-25 17:55:04.383: I/System.out(383): <title>403 Forbidden</title>
11-25 17:55:04.383: I/System.out(383): </head><body>
11-25 17:55:04.403: I/System.out(383): <h1>Forbidden</h1>
11-25 17:55:04.403: I/System.out(383): <p>You don't have permission to access /connection.php
11-25 17:55:04.403: I/System.out(383): on this server.</p>
11-25 17:55:04.403: I/System.out(383): </body></html>
11-25 17:55:04.403: W/System.err(383): java.io.IOException: Attempted read on closed stream.
11-25 17:55:04.483: D/dalvikvm(383): GC_FOR_MALLOC freed 2856 objects / 168704 bytes in 73ms
11-25 17:55:04.483: W/System.err(383): at org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:127)
11-25 17:55:04.483: W/System.err(383): at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:157)
11-25 17:55:04.483: W/System.err(383): at java.io.InputStreamReader.read(InputStreamReader.java:275)
11-25 17:55:04.483: W/System.err(383): at java.io.BufferedReader.fillBuf(BufferedReader.java:155)
11-25 17:55:04.483: W/System.err(383): at java.io.BufferedReader.readLine(BufferedReader.java:386)
11-25 17:55:04.483: W/System.err(383): at com.example.audiobus.WelcomeActivity$getDataFromDatabse.convertString(WelcomeActivity.java:157)
11-25 17:55:04.483: W/System.err(383): at com.example.audiobus.WelcomeActivity$getDataFromDatabse.doInBackground(WelcomeActivity.java:133)
11-25 17:55:04.483: W/System.err(383): at com.example.audiobus.WelcomeActivity$getDataFromDatabse.doInBackground(WelcomeActivity.java:1)
11-25 17:55:04.483: W/System.err(383): at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-25 17:55:04.483: W/System.err(383): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-25 17:55:04.483: W/System.err(383): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-25 17:55:04.483: W/System.err(383): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-25 17:55:04.483: W/System.err(383): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-25 17:55:04.483: W/System.err(383): at java.lang.Thread.run(Thread.java:1096)
11-25 17:55:04.483: I/System.out(383): org.apache.http.conn.EofSensorInputStream@4a372020
11-25 17:55:04.483: I/System.out(383): bottom of convert string
11-25 17:55:04.493: I/TTS received:(383): Connection is not establish, Please restart the Application
1-2517:55:02.473:I/System.out(383):IP为**********
11-2517:55:02.473:I/System.out(383):org.apache.http.client.methods。HttpPost@4a32c610
11-2517:55:02.473:E/welocmeActivity(383):HTTPPost是http://************/connection.php
11-25 17:55:02.763:I/System.out(383):在初始化中高于tts
11-25 17:55:02.763:I/TTS已收到:(383):欢迎使用音频总线,请稍候,我们正在检索信息
11-25 17:55:02.773:I/System.out(383):在初始化时低于tts
11-25 17:55:04.373:I/System.out(383):转换字符串的顶部
11-25 17:55:04.383:I/系统输出(383):
11-25 17:55:04.383:I/系统输出(383):
11-2517:55:04.383:I/系统输出(383):403禁止
11-25 17:55:04.383:I/系统输出(383):
11-2517:55:04.403:I/系统输出(383):禁止
11-2517:55:04.403:I/System.out(383):您没有访问/connection.php的权限
11-2517:55:04.403:I/System.out(383):在此服务器上
11-2517:55:04.403:I/系统输出(383):
11-25 17:55:04.403:W/System.err(383):java.io.IOException:尝试在封闭流上读取。
11-25 17:55:04.483:D/dalvikvm(383):GC_FOR_MALLOC在73毫秒内释放了2856个对象/168704个字节
11-25 17:55:04.483:W/System.err(383):位于org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:127)
11-2517:55:04.483:W/System.err(383):位于org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:157)
11-2517:55:04.483:W/System.err(383):在java.io.InputStreamReader.read(InputStreamReader.java:275)处
11-2517:55:04.483:W/System.err(383):位于java.io.BufferedReader.fillBuf(BufferedReader.java:155)
11-2517:55:04.483:W/System.err(383):在java.io.BufferedReader.readLine(BufferedReader.java:386)
11-25 17:55:04.483:W/System.err(383):在com.example.audiobus.WelcomeActivity$GetDataFromDatabase.convertString(WelcomeActivity.java:157)
11-25 17:55:04.483:W/System.err(383):在com.example.audiobus.WelcomeActivity$GetDatafromDatabase.doInBackground(WelcomeActivity.java:133)
11-25 17:55:04.483:W/System.err(383):在com.example.audiobus.WelcomeActivity$GetDatafromDatabase.doInBackground(WelcomeActivity.java:1)
11-2517:55:04.483:W/System.err(383):在android.os.AsyncTask$2.call(AsyncTask.java:185)
11-25 17:55:04.483:W/System.err(383):在java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-2517:55:04.483:W/System.err(383):在java.util.concurrent.FutureTask.run(FutureTask.java:137)处
11-25 17:55:04.483:W/System.err(383):位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-25 17:55:04.483:W/System.err(383):位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-2517:55:04.483:W/System.err(383):在java.lang.Thread.run(Thread.java:1096)处
11-2517:55:04.483:I/System.out(383):org.apache.http.conn。EofSensorInputStream@4a372020
11-25 17:55:04.483:I/System.out
String tempValue = convertString(is);
System.out.println(tempValue);
System.out.println(is.toString());