You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String at.huber.youtubeExtractor.YtFile.getUrl()' on a null object reference
#214
Open
ldev1211 opened this issue
Nov 18, 2021
· 1 comment
In the first install application in my physic device. I really can download video from youtube to my device's storage. But the next time, my application crashed immediately. Then Android Studio IDE announce to me error in line init String downloadURL like title of this question. This is my code:
String youtubeLink = ("https://www.youtube.com/watch?v=" + videoYT.getId().getVideoId());
YouTubeUriExtractor ytEx = new YouTubeUriExtractor(context) {
@Override
public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
if (ytFiles != null) {
int itag = 22;
String downloadURL = ytFiles.get(itag).getUrl();// line where Android Studio IDE gives an error
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadURL));
String title = URLUtil.guessFileName(downloadURL,null,null);
request.setTitle(title);
request.setDescription("Downloading file...");
String cookie = CookieManager.getInstance().getCookie(downloadURL);
request.addRequestHeader("cookie",cookie);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,title);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
Toast.makeText(context, "Bắt đầu tải xuống...", Toast.LENGTH_SHORT).show();
}
}
};
ytEx.execute(youtubeLink);
The text was updated successfully, but these errors were encountered:
ldev1211
changed the title
Attempt to invoke virtual method 'java.lang.String at.huber.youtubeExtractor.YtFile.getUrl()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String at.huber.youtubeExtractor.YtFile.getUrl()' on a null object reference
Nov 18, 2021
I don't know if u already solved this problem but i had similar problem. For me worked reading what's inside ytFiles array and then I noticed that there's no element with itag = 22 (there was 18, 133, 134, 135) which probably might vary between different videos from youtube.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In the first install application in my physic device. I really can download video from youtube to my device's storage. But the next time, my application crashed immediately. Then Android Studio IDE announce to me error in line init String downloadURL like title of this question. This is my code:
The text was updated successfully, but these errors were encountered: