我的应用程序上有一些崩溃日志。 以下是我的应用项目中的代码。
public class MessageCenter {
private static final String TAG = MessageCenter.class.getSimpleName();
这是发生错误的Java库源。
public String getSimpleName() {
if (isArray()) {
return getComponentType().getSimpleName() + "[]";
}
String name = getName();
if (isAnonymousClass()) {
return "";
}
if (isMemberClass() || isLocalClass()) {
return getInnerClassName();
}
int dot = name.lastIndexOf('.');
if (dot != -1) {
return name.substring(dot + 1);
}
return name;
}
我不知道为什么会这样。 那是Java基础API,没有参数。
它也没有真正重现,我发现它只发生在4.1.2 Android操作系统版本上。 (我不确定其他操作系统版本。)
以下是日志。
03-09 18:24:08.547 W/ImageLoader(19218): memoryCache() and memoryCacheSize() calls overlap each other
03-09 18:24:08.547 W/ImageLoader(19218): diskCache() and diskCacheFileNameGenerator() calls overlap each other
03-09 18:24:08.547 W/ImageLoader(19218): diskCache(), diskCacheSize() and diskCacheFileCount calls overlap each other
03-09 18:24:08.547 W/ImageLoader(19218): diskCache(), diskCacheSize() and diskCacheFileCount calls overlap each other
03-09 18:24:08.547 D/ImageLoader(19218): Initialize ImageLoader with configuration
03-09 18:24:08.547 I/System.out(19218): Couldn't load jnicrash from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.esplanet.lounge-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.esplanet.lounge-1, /vendor/lib, /system/lib]]]: findLibrary returned null
03-09 18:24:08.547 D/dalvikvm(19218): processAnnotationValue failed on default for 'httpMethod'
03-09 18:24:08.547 D/dalvikvm(19218): processAnnotationValue failed on default for 'reportType'
03-09 18:24:08.557 D/CrashLogger(19218): CrashLogger is enabled for com.esplanet.lounge, intializing...
03-09 18:24:08.557 V/TloungeAppApi(19218): [LoungeAppApi] init(Context context) call
03-09 18:24:08.577 V/TloungeAppApi(19218): [LoungeApi] onServiceConnected = 1
03-09 18:24:08.587 V/TloungeAppApi(19218): [LoungeAppApi] call isMdnLogin
03-09 18:24:08.587 V/TloungeAppApi(19218): isMdnLogin() call
03-09 18:24:08.587 W/dalvikvm(19218): Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/esplanet/pp/sdk/MessageCenter;
03-09 18:24:08.587 D/AndroidRuntime(19218): Shutting down VM
03-09 18:24:08.587 W/dalvikvm(19218): threadid=1: thread exiting with uncaught exception (group=0x416bad58)
03-09 18:24:08.587 E/CrashLogger(19218): CrashLogger caught a ExceptionInInitializerError exception for com.esplanet.lounge. Building report.
03-09 18:24:08.587 E/dalvikvm(19218): Invalid debug info stream. class Lcom/esplanet/pp/sdk/MessageCenter;; proto ()V
03-09 18:24:08.687 E/CrashLogger(19218): com.esplanet.lounge fatal error : null
03-09 18:24:08.687 E/CrashLogger(19218): java.lang.ExceptionInInitializerError
03-09 18:24:08.687 E/CrashLogger(19218): at com.esplanet.lounge.core.pushmgr.PushManager.initMessageCenter(PushManager.java:275)
03-09 18:24:08.687 E/CrashLogger(19218): at com.esplanet.lounge.core.pushmgr.PushManager.init(PushManager.java:263)
03-09 18:24:08.687 E/CrashLogger(19218): at com.esplanet.lounge.core.pushmgr.PushManager.access$8(PushManager.java:262)
03-09 18:24:08.687 E/CrashLogger(19218): at com.esplanet.lounge.core.pushmgr.PushManager$6.run(PushManager.java:235)
03-09 18:24:08.687 E/CrashLogger(19218): at android.os.Handler.handleCallback(Handler.java:733)
03-09 18:24:08.687 E/CrashLogger(19218): at android.os.Handler.dispatchMessage(Handler.java:95)
03-09 18:24:08.687 E/CrashLogger(19218): at android.os.Looper.loop(Looper.java:136)
03-09 18:24:08.687 E/CrashLogger(19218): at android.app.ActivityThread.main(ActivityThread.java:5090)
03-09 18:24:08.687 E/CrashLogger(19218): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 18:24:08.687 E/CrashLogger(19218): at java.lang.reflect.Method.invoke(Method.java:515)
03-09 18:24:08.687 E/CrashLogger(19218): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
03-09 18:24:08.687 E/CrashLogger(19218): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
03-09 18:24:08.687 E/CrashLogger(19218): at dalvik.system.NativeStart.main(Native Method)
03-09 18:24:08.687 E/CrashLogger(19218): Caused by: java.lang.NullPointerException
03-09 18:24:08.687 E/CrashLogger(19218): at java.lang.Class.getSimpleName(Class.java:946)
03-09 18:24:08.687 E/CrashLogger(19218): at com.esplanet.pp.sdk.MessageCenter.<clinit>(MessageCenter.java)
03-09 18:24:08.687 E/CrashLogger(19218): ... 13 more
03-09 18:24:08.687 I/Process (19218): Sending signal. PID: 19218 SIG: 9
如果有人想避免例外,请与我联系。 谢谢!
答案 0 :(得分:0)
此
public String getSimpleName() {
if (isArray()) {
return getComponentType().getSimpleName() + "[]";
}
是一个实例方法,因为没有提到静态关键字。您试图在静态上下文中调用该方法,即不在对象上调用该方法,这就是初始化程序错误的原因。 在调用之前,您需要该对象的实例。尝试
private static final String TAG = new MessageCenter().getClass().getSimpleName();
或者如果您想维护静态引用
private static final String TAG = MessageCenter.class.getClass().getSimpleName();