我正在使用反射来查看 Equalizer 类是否可用于 Android OS 2.3 及更高版本,然后使用该类(如果可用)。但是,我会定期收到带有“ExceptionInInitializerError”的崩溃报告。这是堆栈跟踪:
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)
这是引发错误的自定义类:
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();
}
}
}
}
因此,崩溃发生在“Class.forName”行,任何异常都应该被Catch
块捕获。为什么不是?
这种情况偶尔会发生,在过去的 2 个月中,我收到了 5 份不同的崩溃报告。