Why do I get NoClassDefFoundError: java/awt/Desktop?

前端 未结 3 461
难免孤独
难免孤独 2021-01-26 12:55

I\'m trying to open an URI with Swing that I get above error.

What is the reason and how can I fix it?

When I do it in console everything is OK but

相关标签:
3条回答
  • 2021-01-26 13:25

    java.awt.Desktop has been introduced in Java 6. Chances are high you're running your code on different JRE versions.

    0 讨论(0)
  • 2021-01-26 13:26

    NoClassDefFoundError can only be caused by a classpath problem.

    Because Desktop is part of jre, make sure that your classpath contains a reference to the jre library.

    In Eclipse, you can go to run configurations --> Classpath and check there

    UPDATE:

    As Andrew suggested, you can also check you have at least java 1.6

    0 讨论(0)
  • 2021-01-26 13:32

    Doc on NoClassDefFoundError

    The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

    You do have some incorrect classloading happening. Mostly due to wrong class loader chaining.

    0 讨论(0)
提交回复
热议问题