Android使用HttpUrlConnection连接到网站失败

时间:2013-01-08 21:40:02

标签: java android web httpurlconnection

我正在尝试从我正在创建的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

有关如何修复它的任何建议? 干杯

1 个答案:

答案 0 :(得分:1)

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

01-08 21:28:57.990:E / InputDispatcher(165):channel'41621cb0 uk.co.redsquirrelsoftware.assignmenttracker / uk.co.redsquirrelsoftware.assignmenttracker.LoginActivity(server)'〜频道无法恢复,将会被处置!

请参阅此问题的接受答案:

Error: Channel is unrecoverably broken and will be disposed! (PhoneGap)