在 Android 应用程序中使用 commonc 编解码器的 NoSuchMethodError
我按照 这里.代码中没有错误.但是当我运行应用程序并调用使用编解码器的函数时,应用程序停止并需要前关闭.
I added the commons codec from apache.org (commons-codec-1.4.jar) in eclipse for my Android application following the instruction here. There is no error in the code. But when I run the application and call the function that use the codec the application stop and need a fore close.
logCat 中说:
Android 运行时:java.lang.NoSuchMethodError:org.apache.commons.codec.binary.Base64.encodeBase64String
Android Runtime: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String
代码行是:字符串 tmpStr = Base64.encodeBase64String(msg);//msg 是一个字节[]
the codeline is: String tmpStr = Base64.encodeBase64String(msg); //msg is a byte[]
该应用程序适用于最低 SDK 版本 = 7 (Android 2.1),所以我不能使用 Android Base64
The application is for a min SDK version = 7 (Android 2.1), so I can't use Android Base64
知道如何解决这个问题吗?
Any idea how can I solve the problem?
推荐答案
我遇到了完全相同的问题.所以我开始浏览 android 源代码,事实证明 Don 对 Android 实现 org.apache.commons.code.binary 的猜测是正确的.他对访问它的能力是错误的,你可以,但它是 apache commons 的 1.2 版,而不是 1.4 版甚至 1.5 版.您可以在 android 来源.
I experienced the exact same problem. So i started browsing the android source code, and as it turns out Don's guess about Android having an implementation of org.apache.commons.code.binary is correct. he's wrong about the ability to access it, you can, but its version 1.2 of the apache commons, not version 1.4 or even 1.5. You can see for your self in the android source.
另外请注意,这个问题与这篇文章的重复.
Also as a note, this question is a duplicate of this post.
相关文章