Android - decodeBase64崩溃了App [英] Android - decodeBase64 crashes App

查看:172
本文介绍了Android - decodeBase64崩溃了App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须加密一个字符串,但应用程序没有达到加密方法,它在加载时崩溃。

我正在使用Apache Commons Codec库。

  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:类路径:/data/app/com.example.cristiano.automacao-2.apk,JNI路径:/data/data/com.example.cristiano.automacao/lib 
12-03 14:03:31.591 23420-23420 / com.example.cristiano.automacao W / dalvikvm:VFY:无法解析静态方法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:无法解析静态方法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:线程退出与未捕获的异常(组= 0x41c7b438)

有什么线索?



已更新 p>

我将代码更改为:

  public static String key = 1234\" ; 
public static byte [] key_Array = decodeBase64(key);

但现在我有其他错误

  java.lang.NoSuchMethodError:org.apache.commons.codec.binary.Base64.decodeBase64 


解决方案

尝试这样:

  //从base 64 
private static byte [] decodeBase64(String dataToDecode)
{
byte [] dataDecoded = Base64.decode(dataToDecode,Base64.DEFAULT);
return dataDecoded;
}

// base 64中的enconde数据
private static byte [] encodeBase64(byte [] dataToEncode)
{
byte [] dataEncoded = Base64.encode(dataToEncode,Base64.DEFAULT);
return dataEncoded;
}


I have to encrypt a String but the app doesn't reach the encrypt method, it crashes on load.
I'm using Apache Commons Codec library.

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);

For some reason, the app crashes in the third line.

My 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)

Any clue about that?

Updated

I changed the code to this:

public static String key = "1234";
public static byte[] key_Array = decodeBase64(key);

But now I got other error

java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64

解决方案

Try this:

// decode data from base 64
    private static byte[] decodeBase64(String dataToDecode)
        {
            byte[] dataDecoded = Base64.decode(dataToDecode, Base64.DEFAULT);
            return dataDecoded;
        }

//enconde data in base 64
        private static byte[] encodeBase64(byte[] dataToEncode)
        {
            byte[] dataEncoded = Base64.encode(dataToEncode, Base64.DEFAULT);
            return dataEncoded;
        }

这篇关于Android - decodeBase64崩溃了App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆