代码之家  ›  专栏  ›  技术社区  ›  PTN

Cloudmine java.lang.NoClassDefFoundError:无法解析:Lorg/slf4j/LoggerFactory;

  •  2
  • PTN  · 技术社区  · 11 年前

    我正在尝试使用Cloudmine存储一些数据。

    然而,我得到了错误 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; 当我调用initialize()进行授权时。

    我不是在单独的线程上运行。我现在正在测试东西,所以我只需要它,这样当单击按钮时,它就会上传一些来自 EditText 领域。

    这是我的代码

    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("");
    
        }
    }
    

    这是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
    
    3 回复  |  直到 11 年前
        1
  •  5
  •   BNK    11 年前

    正如我所评论的,从 SLF4J distribution 并在项目中用作库。然后,使用 slf4j-api-1.7.12.jar (和 slf4j-android-1.7.12.jar 如果需要)。

        2
  •  2
  •   Franz    7 年前

    我也犯了同样的错误,在github上找到了这个解决方案。

    只需将以下内容添加到您的孙子:

    implementation 'org.slf4j:slf4j-api:1.7.25'
    

    https://github.com/nomis/slf4j-android

        3
  •  1
  •   Gaket    9 年前

    我只在Android 5.0-5.1(一个真正的设备和模拟器)上遇到了同样的问题。当时,我使用了Android Studio 2.3.3和构建工具v26。

    我解决了关闭“即时运行”(Instant Run)的问题,但我没有使用它。

    步骤: 转到文件->设置->构建、执行、部署->即时运行 禁用它(第一个复选框)。