错误java.io.FileNotFound BufferReader与InputStreamReader Java Android

时间:2015-01-12 15:00:39

标签: java android

我希望在我的Android应用程序中从我的数据库中获取一些数据。这是我的代码:

try{
            String nome = (String)arg0[0];
            String stato = (String)arg0[1];
            String link="http://www.example.org/AndroidPage.php";
            String data  = URLEncoder.encode("nome", "UTF-8") + "=" + URLEncoder.encode(nome, "UTF-8");
            data += "&" + URLEncoder.encode("stato", "UTF-8") + "=" + URLEncoder.encode(stato, "UTF-8");
            URL url = new URL(link);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();



           BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder sb = new StringBuilder();

            String line = null;
            // Read Server Response
            while((line = reader.readLine()) != null)
            {
                sb.append(line);
                break;
            }
            return sb.toString();
         }catch(Exception e){
            return new String("exception: " + e.toString());
        }

如果我评论BufferReader语句,我不会收到任何错误。这是错误.. (该文件存在于服务器中) http://i.stack.imgur.com/mb3sc.png

更新: 我解决了这个问题..错误是在php脚本里面,我忘了写一个分号。

1 个答案:

答案 0 :(得分:0)

您是否在清单中添加了Internet权限?

<uses-permission android:name="android.permission.INTERNET" />