我必須加密一個字符串,但應用程序沒有達到加密方法,它在加載時崩潰。
我正在使用Apache Commons Codec庫。Android - decodeBase64崩潰應用程序
private EditText txtPass = (EditText)findViewById(R.id.txtPass);
public String key = txtPass.getText().toString();
public byte[] key_Array = org.apache.commons.codec.binary.Base64.decodeBase64(key);
由於某種原因,應用程序在第三行崩潰。
我的logcat。
12-03 14:03:31.441 23420-23420/com.example.cristiano.automacao V/ActivityThread﹕ Class path: /data/app/com.example.cristiano.automacao-2.apk, JNI path: /data/data/com.example.cristiano.automacao/lib
12-03 14:03:31.591 23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ VFY: unable to resolve static method 8974: Lorg/apache/commons/codec/binary/Base64;.decodeBase64 (Ljava/lang/String;)[B
12-03 14:03:31.601 23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ VFY: unable to resolve static method 8984: Lorg/apache/commons/codec/binary/Base64;.encodeBase64String ([B)Ljava/lang/String;
12-03 14:03:31.611 23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41c7b438)
任何線索?
更新
我改變了代碼如下:
public static String key = "1234";
public static byte[] key_Array = decodeBase64(key);
但現在我有其他錯誤
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
? 你必須導入庫,並簡單地使用「decodeBase64(key);」。 – Wildcopper 2014-12-03 16:24:22
我改變了它。但問題依然存在。我認爲問題在於靜態方法。檢查logcat:「無法解析靜態方法8974」 – Cristiano 2014-12-03 16:37:40