Search code examples
javaandroidruntimeexceptionsoundpoolparcel

java.lang.IllegalStateException: at android.os.Parcel.readException


I see this exception in my Android Vitals:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3303)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: java.lang.IllegalStateException: 
  at android.os.Parcel.readException (Parcel.java:1962)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:183)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:135)
  at android.content.ContentProviderProxy.call (ContentProviderProxy.java:651)
  at android.provider.Settings$NameValueCache.getStringForUser (Settings.java:1996)
  at android.provider.Settings$Global.getStringForUser (Settings.java:10437)
  at android.provider.Settings$Global.getString (Settings.java:10426)
  at android.provider.Settings$Global.getInt (Settings.java:10608)
  at com.android.internal.policy.PhoneWindow.<init> (PhoneWindow.java:385)
  at com.android.internal.policy.HwPhoneWindow.<init> (HwPhoneWindow.java:91)
  at com.android.internal.policy.HwPolicyFactoryImpl.getHwPhoneWindow (HwPolicyFactoryImpl.java:49)
  at com.android.internal.policy.HwPolicyFactory.getHwPhoneWindow (HwPolicyFactory.java:50)
  at android.app.Activity.attach (Activity.java:7314)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3233)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

How does one go about finding out what is the cause, as it doesn't reference any of my code?

The only big change is that I added .m4a files into the RAW resource folder and am using them with SoundPool. I'm guessing it's related to that, and is crashing on launch of the app intermittently.

After searching I found this to add to my build.gradle file:

aaptOptions {
   noCompress "mp3"
}

I added this, substituting mp3 for m4a. Or should it be aac? Am I better to use .wav files perhaps? Thanks.

EDIT: The following sheds more light, i.e. the resource file is not found. Yet most times I run the app it's found ok.

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3303)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.ResourcesImpl.openRawResourceFd (ResourcesImpl.java:380)
  at android.content.res.Resources.openRawResourceFd (Resources.java:1443)
  at android.media.SoundPool.load (SoundPool.java:235)
  at [appname].GlobalVariables.getSoundPool (GlobalVariables.java:553)
  at [appname].MainActivity.onCreate (MainActivity.java:85)
  at android.app.Activity.performCreate (Activity.java:7383)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1218)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3256)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: java.io.FileNotFoundException: 
  at android.content.res.AssetManager.openNonAssetFdNative (AssetManager.java)
  at android.content.res.AssetManager.openNonAssetFd (AssetManager.java:803)
  at android.content.res.ResourcesImpl.openRawResourceFd (ResourcesImpl.java:378)
  at android.content.res.Resources.openRawResourceFd (Resources.java:1443)
  at android.media.SoundPool.load (SoundPool.java:235)
  at [appname].GlobalVariables.getSoundPool (GlobalVariables.java:553)
  at [appname].MainActivity.onCreate (MainActivity.java:85)
  at android.app.Activity.performCreate (Activity.java:7383)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1218)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3256)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

Solution

  • It looks like a platform bug affecting the app's first run after installation. The OS launches the app before all the apk content was extracted and so it encounters missing resources. It probably occurs intermittently due to the varying workload of external storage (depending how many processes are using it at the time). You may notice the same behavior with splash screen drawables, especially when they are large (the first time you run the app you'll see a white/black screen for a longer time before the splash image appears - while the device is unpacking the file).

    The quickest fix would be to delay the loading of the resource until it's ready (by checking repeatedly with exception handling).

    If that's not an option you may try converting your resource to an asset (java/.../res/raw -> /assets) which might push it to the front of the unpacking queue and make it available to the app sooner. However there are no guarantees this will work (all the time).

    The last resort would be to store the sound files (if they aren't too big) in the code/class as byte arrays (but that is ugly). That would ensure the data is loaded at the same time as the code, long before execution.