Import Android library in Java project: Noclassdeffounderror

Asked

Viewed 125 times

0

I am trying to import an Android library into a Java desktop project. But the library doesn’t find any classes that are related to import android.os.

I’m having trouble with class Handler android.os.Handler.

Some substitution for that:

public void run() {
    Looper.prepare();
    handler = new Handler();
    Looper.loop();
}

1 answer

0

If the library in question uses Android features, as is the case of the package android.os, then you won’t be able to use it in a java desktop project. The library was not designed in a way to keep free of platform, so it will be restricted to Android.

  • Ok. From what I’ve researched here, I’ve also come to that conclusion. Thank you. ?

  • I haven’t worked with android for some time, but if I’m not mistaken, Looper allows an android thread to receive messages, and Handler is precisely the reference that allows the connection of the current thread with the other. Any callback passed to the thread should fix this. (I may be wrong, as I said earlier, I no longer remember the android api)

  • I found something equivalent in that answer. http://stackoverflow.com/questions/18628751/how-to-instantiate-handler-in-java#new-Answer Swingutilities.invokeLater(r); substui o Handler.post(r) Thanks Ricardo. I’m new around here and I can’t give you a score yet.

  • Don’t worry man, we’re here to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.