coolerfall / Android-HttpDownloadManager

An useful and effective http/https download manager for Android, support breakpoint downloading.
https://ahdm.coolerfall.com
Apache License 2.0
206 stars 43 forks source link

Fatal Exception: java.lang.NullPointerException #67

Closed AdnanFakhar closed 6 years ago

AdnanFakhar commented 6 years ago

Fatal Exception: java.lang.NullPointerException uriString

android.net.Uri$StringUri. (Uri.java:475) android.net.Uri.parse (Uri.java:437) com.coolerfall.download.OkHttpDownloader.innerRequest (OkHttpDownloader.java:113) com.coolerfall.download.OkHttpDownloader.start (OkHttpDownloader.java:73) com.coolerfall.download.DownloadDispatcher.executeDownload (DownloadDispatcher.java:197) com.coolerfall.download.DownloadDispatcher.run (DownloadDispatcher.java:64)

I am getting this error.

Adnan

coolerfall commented 6 years ago

Did you pass an empty url or invalid url?

AdnanFakhar commented 6 years ago

I am doing in this way with full URL check...

if (listPlay == null || listPlay.size() < 1 || strIndex == null || listPlay.get(index).getMp3TrackUrl() == null){ Toast.makeText(DownloadService.this, "Cannot Download Song this time. Try later!!", Toast.LENGTH_SHORT).show(); stopForeground(true); stopSelf(); // Remove later }

    else  {
        initNotification(index);
        downloadMP3(index);
        Toast.makeText(DownloadService.this, "Downloading Starts...", Toast.LENGTH_SHORT).show();
        // new DownloadFileFromURL(index).execute(listPlay.get(index).getMp3TrackUrl());
    }

if url is not null then it will call downloadMP3(index);

private void downloadMP3(final int position) { DownloadSongDB.getInstance().openDB(DownloadService.this); int ind = DownloadSongDB.getInstance().getDBSize() + 1; songFile = "koyal_" + ind + ".mp3"; DownloadSongDB.getInstance().closeDownloadSongDB();

    File fileToDownload = new File(DownloadService.this.getFilesDir().getAbsolutePath() + "/" + songFile);
    songFile = fileToDownload.getParent() + "/" + songFile;
    Log.e(" download path  ", songFile);

    String url = listPlay.get(position).getMp3TrackUrl().replaceAll(" ", "%20");
    Log.e("Download  mp3 ", url);

    downloadManager =
            new DownloadManager.Builder().context(this)
                    .downloader(OkHttpDownloader.create())
                    .threadPoolSize(12)
                    .build();

    DownloadRequest request = new DownloadRequest.Builder()
            .url(url)
            .retryTime(5)
            .retryInterval(2, TimeUnit.SECONDS)
            .progressInterval(1, TimeUnit.SECONDS)
            .priority(Priority.HIGH)
            .destinationFilePath(songFile)
            .downloadCallback(new DownloadCallback() {.......
coolerfall commented 6 years ago

Could you pls provide the url, I want to thave a test on it.

coolerfall commented 6 years ago

I got the problem, it seems that your download got a redirection, but downloader did not get the Location, then it crashed. I have fix this in #68 into develop branch.