今天記錄一下本身使用androidpn出現的異常處理:java
[pool-1-thread-1] ERROR: org.androidpn.server.xmpp.NET.XmppIoHandlerexceptionCaught : Java.lang.ExceptionInInitializerErrorandroid
這個是第一個異常,這個異常發生以後,會接着不少個以下異常:編碼
[pool-1-thread-10] ERROR: org.androidpn.server.xmpp.Net.XmppIoHandlerexceptionCaught : java.lang.NoClassDefFoundError: Could not initialize class org.androidpn.server.xmpp.ssl.SSLConfigspa
上個禮拜要提交項目的時候才留意到這麼一行異常(由於以前用了struts的token,因此後臺不少token的警告,因此沒有留意長長的一段異常文字),因而本身debug了一下,找到了引發異常的地方,就是一個空指針的異常,說出來還真是沒有什麼得意的地方:.net
private static URL classPath ; static { storeType = Config.getString("xmpp.ssl.storeType", "JKS"); keyStoreLocation = Config.getString("xmpp.ssl.keystore", "conf" + File.separator + "security" + File.separator + "keystore"); keyStoreLocation = <span style="color:#ff0000;">classPath</span>.getPath() + File.separator + keyStoreLocation; keyPass = Config.getString("xmpp.ssl.keypass", "changeit"); trustStoreLocation = Config.getString("xmpp.ssl.truststore", "conf" + File.separator + "security" + File.separator + "truststore"); trustStoreLocation = classPath.getPath() + File.separator + trustStoreLocation; trustPass = Config.getString("xmpp.ssl.trustpass", "changeit"); <span style="color:#ff0000;">classPath</span> = SSLConfig.class.getResource("/");
看到classPath,很明顯,這個classPath會引發空指針異常,因此,只要把classPath = SSLConfig.class.getResource("/");往上提,提到static塊裏面的第一行,就ok了。debug
想來應該是寫這個版本的人有點不當心所致,不過問題不大,仍然感謝他的奉獻精神,各位有看到這種異常的,還但願對你們有幫助。指針
今天(20120801)又看到一個Bug,仍是在SSLConfig上面:code
[pool-1-thread-1] ERROR: org.androidpn.server.xmpp.ssl.SSLConfig<clinit> : SSLConfig startup problem.server
這一個錯誤由路徑錯誤引發,由於編碼格式的問題,若是路徑中存在空格,會變成%20這樣的字符,因此只要確保路徑正確,就ok了。Bug出現仍是在classPath的初始化上面:token
// Load keystore try { keyStore = KeyStore.getInstance(storeType); keyStore.load(new FileInputStream(URLDecoder.decode(keyStoreLocation)), keyPass .toCharArray()); }
仍是在靜態初始化塊這裏,把keyStoreLocation換成這種初始方式就不會出現找不到路徑這樣的錯誤了。
若是有錯,還但願指出。