java.lang.UnsatisfiedLinkError: sun.awt.SunToolkit.getAppContext 异常解决办法

来源:互联网 发布:程序员怎么接私活 编辑:程序博客网 时间:2024/05/22 07:43

第一次在做AWT时候遇到上述异常,弄了几天都没效果,偶然的在国外的一个java论坛上看到

Since version 3.3, SWT automatically finds its required platform-specific libraries, which are inside the swt.jar (at the top level of the JAR contents). So all you need is swt.jar in the classpath, and it works.

One way to get an UnsatisifiedLinkError is if you're using a swt.jar for another platform -- they're all named "swt.jar"; for example, if you download the one for Linux, and try to use it on Windows. The project will compile OK since all the API-level code is the same Java for every platform, but it will fail when you run because the native libraries are wrong.

However, since the error in this case happens in AWT, it might be something else, not directly related to SWT. First, make sure you've downloaded the Windows SWT release. When you import it into your workspace, it creates an Eclipse project named org.eclipse.swt, which contains the swt.jar. You then make org.eclipse.swt a required project for your project, and nothing else in the Build Path besides a valid, clean JRE (you can try defining a new one [Window -> Preferences -> Java -> Installed JREs], or just use a different one you might have installed).

You can also test it from the shell/command window. Go to your project directory. The command should be as simple as:

java -cp bin;../org.eclipse.swt/swt.jar HelloWorldSWT

I got your code to run (Vista-32, JDK 6_15), but the window opened really small, and would not close. I don't know anything about the SWT-AWT bridge though, so good luck with that....

 

照着这样做了效果也没出,还是报异常,

仔细检查了下JDK 和JRE的版本,由于JAVA的自动更新

 jdk的版本没变,而JRE版本不同,比如你的安装目录为C:/JAVA

看下你的该目录下是不是多了一个JRE的更新目录,在控制面板里面去把更新的版本删除就好。。。

】OK

原创粉丝点击