Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jasypt无法在Android 5.1.1及以上版本上初始化,类加载器为空_Android_Nullpointerexception_Classloader_Jasypt - Fatal编程技术网

Jasypt无法在Android 5.1.1及以上版本上初始化,类加载器为空

Jasypt无法在Android 5.1.1及以上版本上初始化,类加载器为空,android,nullpointerexception,classloader,jasypt,Android,Nullpointerexception,Classloader,Jasypt,我使用Jasypt(compile'org.Jasypt:Jasypt:1.9.2')时通常使用标准的PBE加密机 StandardPBEByteEncryptor strongBinaryEncryptor = new StandardPBEByteEncryptor(); strongBinaryEncryptor.setAlgorithm("..."); strongBinaryEncryptor.setKeyObtentionIterations(...);

我使用Jasypt(
compile'org.Jasypt:Jasypt:1.9.2'
)时通常使用标准的PBE加密机

    StandardPBEByteEncryptor strongBinaryEncryptor = new StandardPBEByteEncryptor();
    strongBinaryEncryptor.setAlgorithm("...");
    strongBinaryEncryptor.setKeyObtentionIterations(...);
    strongBinaryEncryptor.setProviderName(BouncyCastleProvider.PROVIDER_NAME);
    strongBinaryEncryptor.setPassword("...");
    byte[] encryptedBytes = strongBinaryEncryptor.encrypt(bytes);
这过去可以正常工作,但现在它崩溃了,出现以下根异常:

E/AndroidRuntime:  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String)' on a null object reference
E/AndroidRuntime:     at org.jasypt.normalization.Normalizer.initializeIcu4j(Normalizer.java:139)
E/AndroidRuntime:     at org.jasypt.normalization.Normalizer.normalizeToNfc(Normalizer.java:96)
E/AndroidRuntime:     at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:661)
E/AndroidRuntime:     at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.encrypt(StandardPBEByteEncryptor.java:873) 
同样的代码也适用于Kitkat手机和棒棒糖模拟器,但例如OnePlusOne会崩溃

如果您查看源代码,您会看到以下内容:

static void initializeIcu4j() throws ClassNotFoundException {        
    Thread.currentThread().getContextClassLoader().loadClass(ICU_NORMALIZER_CLASS_NAME);
    useIcuNormalizer = Boolean.TRUE;
}
这意味着
Thread.currentThread().getContextClassLoader()
null
。这种情况以前没有发生过,我也不知道是什么导致了这种行为的改变。我也不确定我应该怎么做来修复它


有什么想法吗?

基于从Google代码中删除的wiki页面,这实际上在Dalvik中也是一个bug,但在Froyo中提交了一个补丁。然而,艺术似乎重新出现了这个完全相同的问题

很显然,解决方案是在
Activity.onCreate()
中手动初始化类加载器

public class HelloStax extends Activity {
  @Override public void onCreate(Bundle savedInstanceState) {

    ...

    /*
     * Ensure the factory implementation is loaded from the application
     * classpath (which contains the implementation classes), rather than the
     * system classpath (which doesn't).
     */
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    ...
  }