Android测试

时间:2018-01-12 18:24:41

标签: codenameone

我最近写了一个有互联网连接的应用程序。所有进程在模拟器中运行良好,但在Android Studio上,它会抛出java.net.ProtocolException: unexpected end of stream以及以下堆栈跟踪。

1-13 02:12:53.271 6346-6357/com.my.medi I/zygote: NativeAlloc concurrent copying GC freed 17517(1179KB) AllocSpace objects, 95(4MB) LOS objects, 49% free, 6MB/12MB, paused 4.142ms total 928.991ms
01-13 02:13:03.749 6346-6363/com.my.medi I/System.out: New alert generated: Message - No new updates found
01-13 02:13:28.872 6346-6368/com.my.medi D/Medi: [Network Thread] 0:22:30,491 - Exception: java.net.ProtocolException - unexpected end of stream
01-13 02:13:28.884 6346-6368/com.my.medi W/System.err: java.net.ProtocolException: unexpected end of stream
01-13 02:13:28.917 6346-6368/com.my.medi W/System.err:     at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:396)
01-13 02:13:28.919 6346-6368/com.my.medi W/System.err:     at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:371)
01-13 02:13:28.921 6346-6368/com.my.medi W/System.err:     at com.android.tools.profiler.support.network.HttpTracker$InputStreamTracker.read(HttpTracker.java:103)
01-13 02:13:28.923 6346-6368/com.my.medi W/System.err:     at com.codename1.io.BufferedInputStream.read1(BufferedInputStream.java:338)
01-13 02:13:28.930 6346-6368/com.my.medi W/System.err:     at com.codename1.io.BufferedInputStream.read(BufferedInputStream.java:445)
01-13 02:13:28.939 6346-6363/com.my.medi D/Medi: [EDT] 0:22:30,551 - Exception: java.lang.NullPointerException - Attempt to get length of null array
01-13 02:13:28.942 6346-6368/com.my.medi W/System.err:     at com.codename1.io.BufferedInputStream.read(BufferedInputStream.java:668)
01-13 02:13:28.944 6346-6368/com.my.medi W/System.err:     at com.codename1.io.Util.copyNoClose(Util.java:121)
01-13 02:13:28.948 6346-6368/com.my.medi W/System.err:     at com.codename1.io.Util.copy(Util.java:135)
01-13 02:13:28.950 6346-6368/com.my.medi W/System.err:     at com.codename1.io.Util.copy(Util.java:106)
01-13 02:13:28.956 6346-6368/com.my.medi W/System.err:     at com.codename1.io.Util.readInputStream(Util.java:184)
01-13 02:13:28.958 6346-6368/com.my.medi W/System.err:     at com.codename1.io.ConnectionRequest.readResponse(ConnectionRequest.java:1300)
01-13 02:13:28.968 6346-6368/com.my.medi W/System.err:     at com.codename1.io.gzip.GZConnectionRequest.readUnzipedResponse(GZConnectionRequest.java:76)
01-13 02:13:28.973 6346-6368/com.my.medi W/System.err:     at com.codename1.io.gzip.GZConnectionRequest.readResponse(GZConnectionRequest.java:67)
01-13 02:13:28.977 6346-6368/com.my.medi W/System.err:     at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:797)
01-13 02:13:28.979 6346-6368/com.my.medi W/System.err:     at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
01-13 02:13:28.987 6346-6368/com.my.medi W/System.err:     at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
01-13 02:13:28.990 6346-6368/com.my.medi W/System.err:     at java.lang.Thread.run(Thread.java:764)
01-13 02:13:28.991 6346-6363/com.my.medi W/System.err: java.lang.NullPointerException: Attempt to get length of null array
01-13 02:13:29.002 6346-6363/com.my.medi W/System.err:     at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106)
01-13 02:13:29.004 6346-6363/com.my.medi W/System.err:     at com.codename1.io.rest.RequestBuilder.getAsJsonMap(RequestBuilder.java:336)
01-13 02:13:29.007 6346-6363/com.my.medi W/System.err:     at com.my.medi.Server.updateNews(Unknown Source:16)
01-13 02:13:29.010 6346-6363/com.my.medi W/System.err:     at com.wefeel.entry.sqlmodel.NewsQuery.updateNews(Unknown Source:0)
01-13 02:13:29.013 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList.fetchNews(Unknown Source:6)
01-13 02:13:29.017 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList.lambda$new$2(Unknown Source:0)
01-13 02:13:29.019 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList$$Lambda$2.run(Unknown Source:2)
01-13 02:13:29.021 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Component$1.run(Component.java:2076)
01-13 02:13:29.023 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.processSerialCalls(Display.java:1116)
01-13 02:13:29.026 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.edtLoopImpl(Display.java:1060)
01-13 02:13:29.028 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.mainEDTLoop(Display.java:948)
01-13 02:13:29.030 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
01-13 02:13:29.032 6346-6363/com.my.medi W/System.err:     at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
01-13 02:13:29.034 6346-6363/com.my.medi W/System.err:     at java.lang.Thread.run(Thread.java:764)
01-13 02:13:29.162 6346-6363/com.my.medi I/System.out: New alert generated: Message - java.lang.NullPointerException: Attempt to get length of null array
01-13 02:13:29.196 6346-6363/com.my.medi W/System.err: java.lang.NullPointerException: Attempt to get length of null array
01-13 02:13:29.199 6346-6363/com.my.medi W/System.err:     at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106)
01-13 02:13:29.201 6346-6363/com.my.medi W/System.err:     at com.codename1.io.rest.RequestBuilder.getAsJsonMap(RequestBuilder.java:336)
01-13 02:13:29.205 6346-6363/com.my.medi W/System.err:     at com.my.medi.Server.updateNews(Unknown Source:16)
01-13 02:13:29.208 6346-6363/com.my.medi W/System.err:     at com.wefeel.entry.sqlmodel.NewsQuery.updateNews(Unknown Source:0)
01-13 02:13:29.210 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList.fetchNews(Unknown Source:6)
01-13 02:13:29.215 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList.lambda$new$2(Unknown Source:0)
01-13 02:13:29.217 6346-6363/com.my.medi W/System.err:     at com.UI.NewsList$$Lambda$2.run(Unknown Source:2)
01-13 02:13:29.218 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Component$1.run(Component.java:2076)
01-13 02:13:29.256 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.processSerialCalls(Display.java:1116)
01-13 02:13:29.258 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.edtLoopImpl(Display.java:1060)
01-13 02:13:29.266 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.Display.mainEDTLoop(Display.java:948)
01-13 02:13:29.269 6346-6363/com.my.medi W/System.err:     at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
01-13 02:13:29.271 6346-6363/com.my.medi W/System.err:     at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
01-13 02:13:29.277 6346-6363/com.my.medi W/System.err:     at java.lang.Thread.run(Thread.java:764)
01-13 02:13:30.698 6346-6363/com.my.medi V/RenderScript: User-backed allocation failed stride requirement, falling back to separate allocation
01-13 02:13:30.776 6346-6363/com.my.medi I/chatty: uid=10082(com.my.medi) EDT identical 2 lines
01-13 02:13:30.778 6346-6363/com.my.medi V/RenderScript: User-backed allocation failed stride requirement, falling back to separate allocation
01-13 02:13:30.897 6346-6363/com.my.medi V/RenderScript: User-backed allocation failed stride requirement, falling back to separate allocation
01-13 02:13:30.982 6346-6363/com.my.medi I/chatty: uid=10082(com.my.medi) EDT identical 4 lines
01-13 02:13:30.983 6346-6363/com.my.medi V/RenderScript: User-backed allocation failed stride requirement, falling back to separate allocation

快速网络搜索表明问题可能与响应标题有关,但我不确定为什么/如何防止错误。

1 个答案:

答案 0 :(得分:1)

如果您的服务器设置content-length标头并返回不同的字节数,Android将失败。解决方案是将content-length标头设置为-1或实际正确的字节数。