can't find java.awt.Desktop - java

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.

Related

Debugging OpenJDK source-code with eclipse

in my project i want to debug the C/C++ source code of the OpenJDK version 8 using eclipse. For this purpose I have done following:
Compiled the OpenJDK8 with --with-debug-level=slowdebug using this readme.
Imported the sources makefile project into eclipse
Created an eclipse run configuration, executing gdb against the compiled OpenJDK's java.exe and targeting a sample java program. Into this configuration I have attached the JDK source code directory path, so that eclipse is able to translate debug symbols to source-code lines and view them to me (obviously)
With this approach, I am able to debug through the code of files like java.c.
My problem is that somehow I still cannot debug through native code. Like for example java.lang.System.currentTimeMillis().
To me it looked like the libraries were not included into the eclipse gdb-run. I tried to run gdb manually, and it still didn't work to debug through that code section.
Has anybody expirienced same behavior, or did ever try to debug the JDK source code? I guess I am missing something here... Maybe my approach is just not correct for the task? Would be glad to hear any proposal about how to debug the JDK source code propperly.
Thank you in advance.
You may need to force eclipse into debug mode via the top right corner beetle icon.
Another possible option is to use an assert(false) line instead of a break point.
finally, it's possible that you need to specify a compiler in your eclipse project settings.
Keep in mind that the Eclipse debugger does not work for all compilers, usually because of an incompatible linker. I would recommend looking online for a compatibility list.

How to work with NetBeans IDE 8.2 on Windows 7 64-bit with JDK

I've been having trouble using NetBeans IDE 8.2 with JDK on Windows 7 64-bit. NetBeans can compile code, but doesn't run it. I've downloaded all of the necessary files and programs and even consulted with a computer programming teacher, but I haven't been able to work around this issue. The URL displays an image that shows what I get back after attempting to run a code.
https://i.stack.imgur.com/RsEvx.png
I appreciate any help I can get.
Thanks,
--Sam
JavaApplication1.java is still set as your main class.
To change your main class, go into Project Properties -> Run and change "Main Class" to TestClass.java.
Essentially, the compiler is still running whatever main function is found in JavaApplication1.java.
#notyou Also mentioned how you can right click a file and run it directly, instead of changing the project settings. I used to use this but it slipped me! This is super useful.
I'm pretty sure this question has some answers for you.

Accepted the automatic Java update and now can't open Eclipse,

I'm very new to Java and computing in general. Currently taking an intro to programming course revolving around Java.
I got a notification earlier about a Java update when I wasn't using it and accepted it without much thought. I just now tried to open Eclipse to start doing some homework and when I did, all I got was the following message:
A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: C:/Program Files/Java/jre1.8.0_144/bin
I have no idea where to go from here. I can't get in touch with my web developer friend helped me set up Java on my computer originally, and my instructor isn't responding to emails. I've tried to fix things like this myself in the past and have only compounded the problem, so I'm reluctant to try anything I'm not certain about, which is to say I'm reluctant to try anything at all. Any help is appreciated.
First, try to find where your jdk locates. If you don't remember where you have installed it, try to search for jdk or jre folder in C:/Programm Files. Then go to Window -> Preferences -> Java -> Installed JRE's tab in Eclipse and set path to your jdk or jre.
Got it figured out from an old question- just had to change the text to the updated JRE in the Eclipse initializer. Thank you for your help!

Using Java.applet.Applet in Eclipse

I am little .NET oriented, and new to Java stuff. Using Eclipse IDE, whenever i extend my class by Applet as:
class xyz extends Applet{ . . . };
this gives error. and no suitable oauto-fix. i tried importing manually as
import java.applet.Applet;
But this gives error too. I tried to look up for the problem over internet, but only find the way to create applet, not the solution. Kindly guide me. Do I have to import some files in my Eclipse IDE?
(i forgot to mention, I am using it in my Android Application Project)
As Mr. Thompson said, applets don't work in android. The tutorial you posted may does some Android stuff later - however not in that specific tutorial you linked ("But wait until we start developing on Android" [...at some day in the future and in some other tutorial]). And as you may see the first screenshot he selects
"Package Explorer >> New >> Java Project" and not the below Android Application Project.
So did you really (exactly) followed that tutorial step by step? If so, everything should be working. If not you made a mistake or your eclipse is misconfigured.
whenever you import any class using import statement, it will import from JRE which is linked to Eclipse IDE.
If your IDE not linked to JRE then you will get this type of errors.
to remove these errors, first set some settings in Eclipse.
go to window >> Preferences - you can see one screen now.
here you can go to java >> Installed JREs
if there are no JRE then you can add JRE from your local C: drive.
generally you can find your JRE on the location below(if you have windows machine):
C:\Program Files\Java\jre7 (if you have 32 bit OS)
OR
C:\Program Files (x86)\Java\jre7 (if you have 64 bit OS)
you can also set the compiler compliance level same as your JRE version or below to JRE version but not upper version .(for this you can go to java >> compiler)
In your project in Eclipse, check if you have JRE System Library, like this
(source: ibm.com)
If not, Go to Window - Preferences - Java - Installed JREs page to specify the path of your JRE or JDK.

Thinking in java library installation

Hi i've been trying to install the library on Thinking in Java book 4th edition and i hit a very thick brick wall. I've done everything that the guide from the website told me to do and i still can't get the library to work. From what i've read it seems that the problem is from the build.xml files. having no xml knowledge I am clueless about how I have to modify it in order for it to work. In both cmd and eclipse I am getting these error
c:\TIJ4\code\build.xml
Build Failed
c:\TIJ4\code\build.xml:59:J2SE5 required
Can anyone tell me what I should do ?
I am using eclipse if there is a simpler solution by using eclipse rather than ant please help me out. It's been a week now and I still can't make it work.
The important thing to do is to realize that your ant file has a specific java requirement.
Something to try that might fix this very easily : I believe you can remove any references to a specific JDK, and if you have a reasonably up to date JDK, the build will succeed.
The definete fix : Look into the exact (line 59) of your build file, and try to satisfy the java version that line requires. Java is generally backwords compatible -- something designed to run in J2SE5 should run in the latest JDK. Its not terribly difficult to update your JDK (just google for instructions on your OS).
The most common mistake I see is that people who have the java run time installed believe they also have the Java SDK as well.
Does this "install the library" means you want to look at the code and run them in your eclipse? If so I can share my experience with you.
First run the Eclipse.py script; this will add package info to the source code
Create a new Java project in Eclipse, and then just copy all the source code folders to the src source folder in eclipse, these folders will then be recognized as Java packages.
You should be able to run the classes with a main function.
You can also configure which java version to use for this project in Eclipse build path. 1.5 or higher will work.

Categories