本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Android 使用 HttpUrlConnection 连接到网站失败

发布于2025-01-18 21:48     阅读(598)     评论(0)     点赞(12)     收藏(5)


我正在尝试从我正在创建的 Android 应用程序内部连接到我服务器上的网页,但由于某种原因,它似乎在一行上失败了。

Java 代码:

URL url = new URL("http://redsquirrelsoftware.co.uk/android/assignments/androidlogin.php");
HttpURLConnection hConnection = (HttpURLConnection)url.openConnection();
HttpURLConnection.setFollowRedirects(true);

hConnection.setDoOutput(true);
hConnection.setRequestMethod("POST");   

// ERROR OCCURS ON NEXT LINE
PrintStream ps = new PrintStream(hConnection.getOutputStream());
ps.print("email=" + LoginActivity.email + "&" + "pword=" + LoginActivity.password);
ps.close();
hConnection.connect();

LogCat 响应给了我一个 IllegalStateException - 无法访问应用程序密钥,我以前从未见过,也不知道如何修复它。它还提到了 TimerTask.run(),而我的任何代码中都没有这个 - 猜猜它是 Android 自己的一些代码?

01-08 21:28:55.300: E/MtpService(17770): TimerTask.run(): mReason =1
01-08 21:28:57.990: E/InputDispatcher(165): channel '41621cb0 uk.co.redsquirrelsoftware.assignmenttracker/uk.co.redsquirrelsoftware.assignmenttracker.LoginActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-08 21:29:01.870: E/GetJar SDK(17935): PackageMonitor: doOnReceive(): failed
01-08 21:29:01.870: E/GetJar SDK(17935): java.lang.IllegalStateException: Unable to access the application key
01-08 21:29:01.870: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor.doOnReceive(PackageMonitor.java:113)
01-08 21:29:01.870: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor.access$000(PackageMonitor.java:62)
01-08 21:29:01.870: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor$1.run(PackageMonitor.java:87)
01-08 21:29:01.870: E/GetJar SDK(17935):    at java.lang.Thread.run(Thread.java:856)
01-08 21:29:02.230: E/GetJar SDK(17918): PackageMonitor: doOnReceive(): failed
01-08 21:29:02.230: E/GetJar SDK(17918): java.lang.IllegalStateException: Unable to access the application key
01-08 21:29:02.230: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor.doOnReceive(PackageMonitor.java:117)
01-08 21:29:02.230: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor.access$000(PackageMonitor.java:59)
01-08 21:29:02.230: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor$1.run(PackageMonitor.java:84)
01-08 21:29:02.230: E/GetJar SDK(17918):    at java.lang.Thread.run(Thread.java:856)
01-08 21:29:02.470: E/GetJar SDK(17918): PackageMonitor: doOnReceive(): failed
01-08 21:29:02.470: E/GetJar SDK(17918): java.lang.IllegalStateException: Unable to access the application key
01-08 21:29:02.470: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor.doOnReceive(PackageMonitor.java:117)
01-08 21:29:02.470: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor.access$000(PackageMonitor.java:59)
01-08 21:29:02.470: E/GetJar SDK(17918):    at com.getjar.sdk.data.metadata.PackageMonitor$1.run(PackageMonitor.java:84)
01-08 21:29:02.470: E/GetJar SDK(17918):    at java.lang.Thread.run(Thread.java:856)
01-08 21:29:02.500: E/GetJar SDK(17935): PackageMonitor: doOnReceive(): failed
01-08 21:29:02.500: E/GetJar SDK(17935): java.lang.IllegalStateException: Unable to access the application key
01-08 21:29:02.500: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor.doOnReceive(PackageMonitor.java:113)
01-08 21:29:02.500: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor.access$000(PackageMonitor.java:62)
01-08 21:29:02.500: E/GetJar SDK(17935):    at com.getjar.sdk.data.metadata.PackageMonitor$1.run(PackageMonitor.java:87)
01-08 21:29:02.500: E/GetJar SDK(17935):    at java.lang.Thread.run(Thread.java:856)
01-08 21:29:17.530: E/dalvikvm(18081): Could not find class 'com.google.common.collect.HashMultiset', referenced from method com.fasterxml.jackson.datatype.guava.GuavaDeserializers.findCollectionDeserializer
01-08 21:29:17.540: E/dalvikvm(18081): Could not find class 'com.google.common.collect.EnumBiMap', referenced from method com.fasterxml.jackson.datatype.guava.GuavaDeserializers.findMapDeserializer
01-08 21:29:17.540: E/dalvikvm(18081): Could not find class 'com.google.common.collect.ImmutableSetMultimap', referenced from method com.fasterxml.jackson.datatype.guava.GuavaDeserializers.findMapLikeDeserializer
01-08 21:29:17.540: E/dalvikvm(18081): Could not find class 'com.google.common.collect.Table', referenced from method com.fasterxml.jackson.datatype.guava.GuavaDeserializers.findMapLikeDeserializer

关于如何修复它,您有什么建议吗?谢谢


解决方案


我认为日志中的相关行是:

01-08 21:28:57.990:E/InputDispatcher(165):通道“41621cb0 uk.co.redsquirrelsoftware.assignmenttracker/uk.co.redsquirrelsoftware.assignmenttracker.LoginActivity(服务器)”〜通道已不可恢复地损坏,将被处置!

请参阅该问题的可接受答案:

错误:通道已不可恢复并被丢弃!(PhoneGap)



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/695235/0806da7570b38ec30af5/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

12 0
收藏该文
已收藏

评论内容:(最多支持255个字符)