I’m using reflection to see if the Equalizer class is available for Android OS 2.3 and higher, and then use that class if it is available. However, I’m periodically getting crash reports with the “ExceptionInInitializerError”. Here are the stacktrace:
java.lang.ExceptionInInitializerError
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:234)
at java.lang.Class.forName(Class.java:181)
at com.myapp.EQ.<init>(SourceFile:16)
at com.myapp.mainAct.onCreate(SourceFile:209)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1312]: 277 cannot locate '_ZN7android11AudioEffect25queryDefaultPreProcessingEiP19effect_descriptor_sPj'...
at java.lang.Runtime.loadLibrary(Runtime.java:455)
at java.lang.System.loadLibrary(System.java:554)
at android.media.audiofx.AudioEffect.<clinit>(AudioEffect.java:63)
And here’s the custom class where the error is getting thrown:
public class EQ{
private Class<?> eqClass = null;
public EQ(){
if(Build.VERSION.SDK_INT >= 9){
try {
eqClass = Class.forName("android.media.audiofx.Equalizer");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
So, the crash happens at the “Class.forName” line, and any exception should be caught by the Catch block. Why isn’t it?
This happens sporadically, and I’ve received 5 different crash reports over the last 2 months.
java.lang.ExceptionInInitializerErroris not anExceptionand thus can’t be caught using yourtry catchblock.The java docs say its a child of
ErrorInstead try catching that specifc type of error like this: