[英]Cloudmine java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
I am trying to store some data using Cloudmine. 我正在尝试使用Cloudmine存储一些数据。
However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
但是,我收到错误
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
when I call initialize() for authorization. 当我调用initialize()进行授权时。
I'm not running on a separate thread or something. 我没有在单独的线程上运行。 I'm testing stuff out right now so I just have it so that when a button is clicked, it uploads some information from some
EditText
fields. 我现在正在测试东西,所以只有它,以便单击按钮时,它会从一些
EditText
字段上载一些信息。
This is my code 这是我的代码
public class ButtonClick implements View.OnClickListener {
private MainWindowActivity mainWindowActivity;
public ButtonClick(MainWindowActivity mainWindowActivity, Button doneBtn, Button addBtn) {
this.mainWindowActivity = mainWindowActivity;
addBtn.setEnabled(true);
addBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// This will initialize your credentials
// ERROR HERE
CMApiCredentials initialize = CMApiCredentials.initialize("id", "key");
SimpleCMObject location = new SimpleCMObject();
location.add("address", Runner.getAddressStr());
location.add("city", Runner.getCityStr());
location.add("state", Runner.getStateStr());
location.add("zip", Runner.getZipStr());
location.save(new ObjectModificationResponseCallback() {
public void onCompletion(ObjectModificationResponse response) {
Toast.makeText(mainWindowActivity, "Location saved: " + response.wasSuccess(), Toast.LENGTH_SHORT).show();
}
});
EditText address = (EditText) mainWindowActivity.findViewById(R.id.address);
address.setText("");
EditText city = (EditText) mainWindowActivity.findViewById(R.id.city);
city.setText("");
EditText state = (EditText) mainWindowActivity.findViewById(R.id.state);
state.setText("");
EditText zip = (EditText) mainWindowActivity.findViewById(R.id.zip);
zip.setText("");
}
}
This is the Logcat: 这是Logcat:
Process: prog, PID: 26580
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/prog-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
As I have commented, download zip file from SLF4J distribution and use as library in your project. 正如我所评论的,从SLF4J发行版下载zip文件,并在您的项目中用作库。 Then, use
slf4j-api-1.7.12.jar
(and slf4j-android-1.7.12.jar
if needed). 然后,使用
slf4j-api-1.7.12.jar
(如果需要,请使用slf4j-api-1.7.12.jar
slf4j-android-1.7.12.jar
)。
I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). 我只有在Android 5.0-5.1(真实的设备和模拟器)上遇到过相同的问题。 At that moment, I used Android Studio 2.3.3 and build tools v26.
那时,我使用了Android Studio 2.3.3和构建工具v26。
I solved the problem turning off Instant Run that I didn't use anyway. 我解决了关闭我从未使用过的Instant Run的问题。
Steps: go to File -> Settings -> Build, Execution, Deployment -> Instant run Disable it (first checkbox). 步骤:转到文件->设置->构建,执行,部署->即时运行禁用它(第一个复选框)。
I had the same error and found this solution on github. 我有同样的错误,并在github上找到了此解决方案。
Just add the following to your grandle: 只需将以下内容添加到您的框框即可:
implementation 'org.slf4j:slf4j-api:1.7.25'
https://github.com/nomis/slf4j-android https://github.com/nomis/slf4j-android
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.