java.io.file url,Android的URL连接java.io.FileNotFoundException

如果我开这跟我的Web浏览器的一切工作正常。如果我通过Android应用程序打开它,则会抛出java.io.FileNotFoundException。

Android的代码:

class SendComment extends AsyncTask {

protected String doInBackground(String... urls) {

String _output = null;

try {

URL url = new URL(urls[0]);

BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openStream()));

_output = buffer.readLine();

buffer.close();

} catch (IOException e) {

e.printStackTrace();

}

return _output;

}

protected void onPostExecute(String result) {

}

}

但是当我删除 “@” 或在的 “.COM” E-mail地址甚至适用于Android。看起来好像一个可用的电子邮件地址是导致崩溃的原因。

这是堆栈跟踪:

java.io.FileNotFoundException: http://localhost.com/api/submit_comment?post_id=23856&name=Max&email=Max.Mustermann%40googlemail.com&content=hallo

at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206)

at java.net.URL.openStream(URL.java:470)

at de.example.app.SendComment.doInBackground(ServerManager.java:230)

at de.example.app.SendComment.doInBackground(ServerManager.java:1)

at android.os.AsyncTask$2.call(AsyncTask.java:292)

at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

at java.lang.Thread.run(Thread.java:818)

2015-06-16

Jan

+0

从logcat的StackTrace?无论如何,我相信这可能只是一个URLEncode问题:https://developer.android.com/reference/java/net/URLEncoder.html –

+1

您的手机是否连接到与您的计算机相同的网络? 尝试在手机的WebBrowser上打开此URL并查看它是否有效。 另外,请尝试在“?”之前移除“/”,如下所示:http://localhost.com/api/submit_comment?post_id=12345&name=Max&[email protected]&content=hallo –

+0

例外是抛出,不返回。当你发布堆栈跟踪时,你会发现BufferedReader与它无关。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值