Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

397
Views
How to resolve NullPointerException on HttpURLConnection?

I am developing an Android application, using ExoPlayer for video playback, Glide for image display, and a download library for file download, and they all have NullPointerException related to HttpURLConnection, I'm sure the link used is available.

The magic is, I just follow these library's The method described in the official documentation loads the data normally, and this error occurs from time to time, and the three libraries may not throw NullPointerException at the same time, and I don't even know how to reproduce this problem.

This is the error thrown by ExoPlayer, which prevents the video from loading:

E/LoadTask: Unexpected exception loading stream
      java.lang.NullPointerException: wrapped.getHeaderField(key) must not be null
        at com.android.tools.appinspection.network.httpurl.TrackedHttpURLConnection.getHeaderField(TrackedHttpURLConnection.kt:317)
        at com.android.tools.appinspection.network.httpurl.HttpsURLConnectionWrapper.getHeaderField(HttpsURLConnectionWrapper.kt:182)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.isCompressed(DefaultHttpDataSource.java:829)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:413)
        at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1009)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

The video playback part of the code is as follows:

            val factory = ProgressiveMediaSource.Factory(
                DefaultHttpDataSource.Factory()
            )
            val mediaSource = arrayListOf<MediaSource>(
                factory.createMediaSource(MediaItem.fromUri(video.base_url)),
                factory.createMediaSource(MediaItem.fromUri(audio.base_url))
            )
            val media = MergingMediaSource(true, *mediaSource.toTypedArray())
            ViewModel.getPlayer()?.let { player ->
                player.setMediaSource(media)
                player.prepare()
            }

And this is the error thrown by Aria, which cause software to crash:

E/AndroidRuntime: FATAL EXCEPTION: pool-5-thread-2
    Process: io.github.sgpublic.bilidownload, PID: 22400
    java.lang.NullPointerException: wrapped.getRequestProperty(field) must not be null
        at com.android.tools.appinspection.network.httpurl.TrackedHttpURLConnection.getRequestProperty(TrackedHttpURLConnection.kt:235)
        at com.android.tools.appinspection.network.httpurl.HttpsURLConnectionWrapper.getRequestProperty(HttpsURLConnectionWrapper.kt:274)
        at com.arialyy.aria.http.ConnectionHelp.setConnectParam(ConnectionHelp.java:146)
        at com.arialyy.aria.http.download.HttpDFileInfoTask.run(HttpDFileInfoTask.java:82)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

I have tried Invalidate and Restart, and even uninstalled and reinstalled Android Studio completely, but the problem still cannot be solved, so what is the problem?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found the related entry, and to sum it up this is a bug in the TrackedHttpURLConnection implementation, the fix will be capped around mid-late March.

Update: (Mar 4, 2022 07:09AM)

Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:

Android Studio Dolphin Canary 5 (2021.3.1.5)
Android Gradle Plugin 7.3.0-alpha05
We encourage you to try the latest update.

If you notice further issues or have questions, please file a new bug report.

Thank you for taking the time to submit feedback — we really appreciate it!
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!