简体   繁体   中英

can't find java.awt.Desktop

I'm looking for the class java.awt.Desktop

I think it has something to do with Swing, but I'm not sure what that is. From the little bit I read, It only exists on Java 1.6, which I'm using. Still, under java.awt, all I have is "font".

Is anyone familiar with this? Can tell me if I have to download anything in order for this to work?

Thanks!

the most probable cause is that you have different java version installed next to 1.6 and you messed up your compiler settings. Make really sure that you're compiling against java 1.6 by running following in your java program:

System.out.println(System.getProperty("java.version"));

open Window > Show View > Console to see what the program prints. Also, both Console View and Debug View show the jre used to execute the program. If this shows that eclipse didn't use java 1.6, then go to project properties > java build path > Libraries > JRE System Library ... or have a look at Window > Preferences > Java > Installed JREs

We had the same problem in IntelliJ. We found out that the project-sdk we were using was Android 4.0.3 Platform. We just changed it to 1.6.0_25 java. Then we could import java.awt.Desktop . Kinda makes sense given that awt classes aren't available on Android. Its funny that the code ran fine even though the IDE showed us compile errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM