Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Cloudmine java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

Ask Question

I am trying to store some data using Cloudmine.

However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; when I call initialize() for authorization.

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.

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:

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
                Have you tried to download jar file from SLF4J distribution and use as library in your project?
– BNK
                Aug 20, 2015 at 6:15
                Do you know which one should I use? I tried the api.jar and the sdk.jar but none of them worked.
– PTN
                Aug 20, 2015 at 16:41

I had the same error and found this solution on github.

Just add the following to your grandle:

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

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

I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). At that moment, I used Android Studio 2.3.3 and build tools v26.

I solved the problem turning off Instant Run that I didn't use anyway.

Steps: go to File -> Settings -> Build, Execution, Deployment -> Instant run Disable it (first checkbox).

Me too. But it did help in this and a couple of other strange cases for us. So it is kind of empirical. – Gaket Dec 17, 2018 at 23:04 Maybe it helps, but I think it's always a good idea to look for other solutions before recommending disabling some helpers. In special in cases where the error is really obvious, like above where android simply says it can not load a Class. – Franz Dec 19, 2018 at 8:21 Emmm. But what if the class actually exists but you get the issue as in our case? For me, it is not obvious when some build time optimizers break the build. You spend half a day trying to understand why this thing can't be built when you've tried both to add the dependency to dependency list and even just downloaded a jar file, putting it into the lib folder and adding it to the dependencies list. – Gaket Dec 19, 2018 at 18:46 Moreover, when your colleagues can build the same project cloned from the same repo. And the solution with adding a library already existed at the moment of my post, so it was unnecessary to duplicate it. So, welcome to our world, @Franzi, where similar issues can often have different and not always beautiful solutions :) – Gaket Dec 19, 2018 at 18:49 It solves it because "Instant Run" is buggy AF. Chances are that you can solve it also just by cleaning and rebuilding the project, but it will fail again sooner than later if Instant Run is enabled. It seems sometimes it fails to install all the stuff needed or whatever. I have seen similar problems also when you are using two different computers to develop an application with the same android device. You install it on one computer, then move to the other, and Instant Run starts breaking shit. I'm going to leave it disabled from now on, it makes me waste more time than it saves. – Fran Marzoa Aug 7, 2019 at 13:28

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.