我导入后的下一步骤公地编解码器1.10.jar:Android Studio中java.lang.NoSuchMethodError与导入库
- 在德的应用程序目录中创建手动复制的一个libs目录
- 。 libs目录内的罐子
- 右击Android的工作室里面的.jar和点击添加为库
加入这一行我build.grade
compile fileTree(dir: 'libs', include: ['*.jar'])
在我的课堂我进口这样的库:
import org.apache.commons.codec.binary.Base64;
然后我试图访问encodeBase64String静态方法中的Base64这样的:
public static class DoThisThing {
public String DoThisOtherThing() {
String hashed = "hello";
String hash = Base64.encodeBase64String(hashed.getBytes());
return hash;
}
}
public class ActivityThing extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_thing);
String hash = DoThisThing.DoThisOtherThing();
System.out.println(hash);
}
}
没有出现错误,甚至当我编译,除了当我运行的应用程序,它会抛出以下错误和应用程序关闭:
11-03 09:41:27.719 2390-2476/com.myproject E/AndroidRuntime: Caused by: java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
我的DoThisThing类不在活动的内部,只是为了缩短它。我检查了库,确实encodeBase64String是静态的。所以我不知道该怎么做,我在java和android环境中是新手。所以,任何帮助将不胜感激
这可能会帮助你 –
Omg谢谢。这似乎很有帮助。我会让你知道我做了什么 –