android - URL check resume method in java -


I have written this method for the check url.

  throws public boolean checksum (string URL) IOException {HttpURLConnection urlc; Urlc = (HttpURLConnection) New URL (url) .openConnection (); Urlc.setRequestProperty ("Range", "Bytes =" + 1 + "-"); Urlc.getResponseCode (); Logs. ("Check Regumed", urlc.getHeaderField ("Acceptable-Range"). ToString ()); If ((urlc.getHeaderField ("acceptable-range"). Equals ("bytes")) {back true; } Other {return false; }}  

While importing the URL with the ability to continue with the URL, this method can not be a bug, the return is "true".

However, when the URL is imported without the ability to continue the URL, the example for the crashed app and the URL

example

log

: < / P>

  08-01 13: 25: 12.201: E / Android Time (8466): Files Exception: Main 08-01 13: 25: 12.201: E / Android Time (8466): Process: Com. Yuxu Download, PID: 8466 08-01 13: 25: 12.201: E / Android Runtime (8466): Java.lang.RuntimeException: service com.yyxu.download.services.DownloadService@429f1b38 unable to get started {act = com.yyxu .download.services.IDownloadService (additional)}: java.lang.NullPointerException 08-01 13: 25: 12.201: E / Android Rendime (8466): Android. App Activitatand handles service (ActivityTrad.Java 2877) 08-01 13: 25: 12.201: E / Android Time (8466): Android. App ActiveTrade $ 2200 (ActivityTrad.JVRITI) 08-01 13: 25: 12.201: E / Android Time (8466): Android. App ActivatedTrade $ H Hondal Message (ActivityThread.java:1362) 08-01 13: 25: 12.201: E / Android Time (8466): Android.OSHandler DiskPachmail (Handler. Java 1.02) 08-01 13: 25: 12.201: E / Android Time (8466): Android. On Los Loop Loop (Looper.Java 157) 08-01 13: 25: 12.201: E / Android Time (8466): Android.AP.ActivateTrade.Mine (ActivityTrad.Java / 35356) 08 -01 13: 25: 12.201: E / Android Random (8466): at java.lang.reflect.Method.invokeNative (Basic Method) 08-01 13: 25: 12.201: E / Android Time (8466): at java.lang. Reflect.Method.invoke (Method.java / 15) 08-01 13: 25: 12.201: E / Android Time (8466): com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1265) 08 -01 13: 25: 12.201: e / Androidrentaim (8466): on com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1081) 08-01 13: 25: 12.201: e / Androidrentaim (8466): on DalvikksystemkNativeStartkmain (Basic Law) 08-01 13: 25: 12.201: e / Androidrentaim (8466) by: java.lang.NullPointerException 08-01 13: 25: 12.201: e / Androidrentaim (8466 ): Com.yyxu.download.services.downloadTask.checkresume (DownloadTask.java:92) 08-01 13: 25: 12.201: E / AndroDendime (8466): at com.yyxu.download.services. Download the download. & Lt; Init & gt; (DownloadTask.java:76) 08-01 13: 25: 12.201: E / Android Rentaim (8466): On com.yyxu.download.services.downloadManager.newDownloadTask (DownloadManager.javaitter17) 08-01 13: 25: 12.201: E / Android Runtime (8466): com.yyxu.download.services.download on Manager.newDownloadTask (DownloadManager.java:342) 08-01 13: 25: 12.201: E / Android Time (8466): .download at com.yyxu. Services.DownloadManager.addTask (DownloadManager.java:86) 08-01 13: 25: 12.201: E / Android Time (8466): at com.yyxu.download.services. Download Service.Onstart (DownloadService: Java: 58) 08-01 13: 25: 12.201: E / Android Rendime (8466): Android. App Service. Onstart Commands (Service Java Script) 08-01 13: 25: 12.201: E / Android Time (8466): App.ActivityThread.handleServiceArgs on Android (ActivityThread.java:2860) 08-01 13: 25: 12.201: E / AndroidRuntim e (8466) ... 10 more  

the problem is com.yyxu.download.services.DownloadTask.checkresume (DownloadTask.java:92)

line 92 is: Log.e ("resume check", urlc.getHeaderField ("acceptable-range"). ToString ());

Please help

the value of the named header field , Or zero if there is no such field in the header. This method returns the string , so toString () .

There is no need to use it means that your URLConnection is not the heading code acceptance-category . Make sure you are using the exact header name as this case is sensitive. You can also use the HttpURLConnection method to get the headers from the number return nth header. But more than that, you should check it before using null to avoid NPE :

  if (urlc. GetHeaderField ("Accept - Rise")! = Faucet) {// ... Go Forward  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -