Using Java.applet.Applet in Eclipse - java

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.

Related

Netbeans 11 Javadoc Not Appearing?

I have a question very similar to Javadocs are not appearing on Apache netbeans for java 10 in the sense that I can't seem to add javadoc support to my Apache Netbeans 11 release, or the maven project that I'm working on.
Here is the overview that I have:
As you can see, the javadoc is added in the URL section, but it does not appear in the code editor, even after a restart.
The URL I added: https://docs.oracle.com/en/java/javase/11/docs/api/index.html
But this doesn't work.
How can I resolve this?
Whilst Netbeans 11 runs well with Ubuntu 18's apt packet "openjdk-11-jdk", when it comes to NB's source-editor's pop-up-Javadoc and "show Javadoc" function (which opens an external browser), both NB functions don't work on a standard Ubuntu installation.
Because NB's Javadoc functions seem so dislike the "openjdk-11-jdk" packet's file structure in "/usr/lib/jvm/java-11-openjdk-…" which is slightly different to the one from the downloadable Openjdk11 zip bundle.
Here's the solution to make both functions work:
Download the Openjdk11 zip bundle for Linux from the Openjdk's website: https://jdk.java.net/archive/
Unzip it, so that its content is in a folder, like for example "openjdk11"
In NB go to the menu "Tools → Java platforms". Add a new platform and select the unzipped folder (openjdk11 for example). NB finds out the correct sources folders inside the src.zip file.
Finally in your NB project property, change in "Libraries" the "Java Platform" to your newly added Openjdk11 platform, and now NB's pop-up-Javadoc works again.
To also have NB's "show Javadoc" functionality, do this additional step please:
Download Oracle's Javadoc11 zip file and unzip it.
Now go to NB's "Java platform" dialogue again and. In the previously added platform "Openjdk11" go to the third tab named "Javadoc" and add as folders all the "java*" subfolders inside the "doc/api/" folder.
That's it. Hope it helps.
Btw, now NB still runs inside Ubuntu's installed Openjdk11 JVM (from the paket "openjdk-11-jdk") and will get apt-automatic updates, however your projects use the unzipped JVM to run. This is no big deal however, since NB always uses a new instance of its used JVM or of the project's JVM to run a project.
I've yet to see somebody who managed to add Javadoc 11 to Netbeans 11.
But there's a work-around which seems to work for many JDK classes, but not for all. If anybody knows how to solve the problem for all JDK classes, please say so, thanks.
Here's the workaround, doing well under Ubuntu 18 Linux with Openjdk11 from the Ubuntu repository, and probably also under other platforms:
Firstly it's strange how we have to add the Javadoc at all. In NB's menu Tools → Java Platforms there's a tab Sources and Javadoc.
1) I tried to use the tab Javadoc first, and had to add all the folders beginning with "java." from the main folder "javadoc/api/" from an unzipped Javadoc11 bundle. This way some JDK functions show the correct Javadoc pop-up help, however many functions just show an empty space, like for example when in Netbeans I enter:
BigInteger big;
big. _
Then the pop-up comes and lists all BigInteger functions but their Javadoc is empty each.
So I tried another approach:
2) From the same NB menu Tools → Java Platforms in the tab Javadoc I removed all entries, and used the other tab Sources where I added all the folders beginning with "java." from an unzipped Java11 source bundle (file src.zip).
This way for many more JDK classes and functions their pop-up window works fine, like the mentioned BigInterger one.
However for certain classes from the java.sql package and probably from others, too, I can't make it to work.
For example I enter in NB:
java.sql.Statement stat;
stat. _
Then I get a pop-up listing all functions, but for many there's a message Javadoc not found in the pop-up window. Like these functions:
stat.addBatch(…)
stat.execute(…)
stat.executeUpdate(…)
etc.
For the following functions however the pop-up window shows the correct Javadoc:
stat.cancel(…)
stat.close(…)
stat.executeBatch(…)
etc.
If you are on an Ubuntu or Debian based OS, in the apt repository there is an specific package for the documentation separated from the JDK that you need to install. Once done, you only need to search for the api folder inside of the docs and set it in the platforms configuration.
Search your Java version package:
sudo apt-cache search java* | grep jdk
Install the version you need (I have installed two of them):
sudo apt-get install openjdk-8-doc openjdk-11-doc
Search for the api folder, I have found it for OpenJDK-11 in /usr/lib/jvm/java-11-openjdk-amd64/docs/api and for OpenJDK-8 in /usr/lib/jvm/java-8-openjdk-amd64/docs/jdk/api. The location will depend on where your JDK is installed, but should be a quite similar path if you have installed it with apt.
Set that path in the platform configuration of Netbeans.
Done with Ubuntu 20.04 and Netbeans 12. Hope it helps other people.

Eclipse - Unable to install breakpoint in a Java API Class

I have found a few question about the issue here on StackOverlow, but all were about own written code. My problem is a bit different, because I want to debug a Java API class, named javax.swing.JComponent.
My first problem was, that I couldn't see any sources. I fixed it described like here Attach the Java Source Code by attaching the source to rt.jar.
Now I see the source and I want to set a breakpoint in the JComponent class. If I try so, I get the error message:
"Modify compiler options to generate line number attributes". That is a nice proposal. But my JDK version was already compiled when I downloaded it..
So, do I have it to compile on my own? Or do you have other advices?
Thanks for your help!
P.S.: I have installed
- Eclipse Neon
- jdk1.8.0_91
- Windows 10 (64 Bit)
One probable issue could come from your application server in IDE pointing to JRE instead of JDK.
Try verifying:
Window -> Preferences --> Server --> runtime environments
<Your-Application-Server> --> edit
Select a JDK instead of JRE
Not sure if you have gone through this link.... has few solutions which worked for some.
Eclipse - Unable to install breakpoint due to missing line number attributes
this happens when you use JRE on your build path in this case.
Try do this:
Window -> Preferences --> Java --> Installed JRES-->then use jdk as default JRE
problem fixed!

Can not get the help or documentation of eclipse while typing

I work on Eclipse Luna on my windows 7, which I downloaded from their site in the usual way.
(Eclipse IDE for Java Developers, Version: Luna Service Release 1 (4.4.1))
While typing a new existing class or method for example, I can not see the documentation,
I just see arg0, arg1 and so on, but no online help with detailed information for every parameter. I know it's possible because I saw it in other places where Eclipse is installed.
How can I get it? From where exactly can I download it? I could not find it.
You can find eclipse.ini in your Eclipse instalation folder.
Open it with notepad / notepad++ / sublime etc. and add:
-vm <"Java SDK Path"> (for example your path could be C:\Program Files\Java\jdk1.8.0_20\bin\javaw.exe)
With this you will set default JDK for your eclipse instalation
Another way to do it. Click with the right mouse button over your project:
Package Explorer -> Configure Build Path
Libraries
Add Library -> JRE System Library
Change the JRE to JDK
Another way is to try opening the declaration of some util class (Ctrl + click over the class). In the window appeared you can click "Attach source.." button and you can choose the path to your JDK.

Eclipse does not start when I run the exe?

When I run the Eclipse.exe within the given folder, it will not start. The Eclipse splash screen will appear for a split second then close. There are no errors.
I've tried practically everything. Updating JDK and JRE: I installed JRE 7 and JDK 1.7.0_40. Both 64 bit, and they are both in the (x86) folder. I've tried re-installing them. And re-downloading Eclipse. Same result every time. I've added the VM to the config, still nothing.
I use Windows 7 and the standard Eclipse for Java IDE.
Go to your Workspace folder then go to Metadata > plugins.
Delete everything from this folder. Then it will work.
Warning: This will delete every configuration from Eclipse!
eclipse.exe -clean -clearPersistedState
All you have to do is go the dir where your eclipse.exe is there and run the above command
The same thing was happening for me. All I had to do was uninstalled Java Update 8
go to : "C:\workspace.metadata.plugins\org.eclipse.e4.workbench"
if already you save backup file "workbench.xmi" replace it else delete this.
This also happened to me. I tried some of the solutions above but couldn't get it done. What i have to do was reinstall the JRE/JDK again and it worked!
When i executed the command "java-version" in cmd, i was getting an error trying to load a class and then when i reinstalled JRE/JDK, it worked all good!
I looked online and found a person who had a similar problem.
It says on the forum
"You might need to download JRE 64 bit version"
But again, it depends on what OS you're using as well.
Kindly check the following:
1) Your eclipse version,whether it is compatible with what version of java.
Have that.
2)Check the operating system specific BIT requirements either 32/64 with eclipse version.
3)Usually java will be installed in ProgramFiles for Java if both OS & Java are 64 bit else it will be in ProgramFiles(x86) if java is 32bit and OS is 64Bit.
4)Last but not least check the environment variables for Java whether it meets the requirements of your eclipse version.
Hope this Helps you!
What system you have - 32-bit or 64-bit? You say it was installed into (x86) folder. But normally (x86) is a default for the 32-bit JDK, not for 64-bit JDK. If you used defaults, then it seems that you installed 32-bit JDK instead of 64-bit.
The actual issue should be with the OS architecture, the JDK (32bit or 64 bit) installed and the eclipse type u installed.
Bring them in sync, things would work completely fine.
Just have a check at the Eventlog as mentioned by #Viji
Ideally u should encounter error like RADAR_PRE_LEAK_64
If its a Java version problem, you can edit the eclipse.ini file and assign the compatible version to the application through adding these lines:
windows example:
-vm
C:\jdk1.7.0_21\bin\javaw.exe
for more information:
https://wiki.eclipse.org/Eclipse.ini
Press Win key + X
click 'System' link from popup menu
click advance setting link (Left panel) in opened 'System setting' window (Control Panel\System and Security\System)
Now a window named 'System property' will be open, select 'advance' tab and click on environmental variables
Select path variable from 'System Variable' list section. and click edit
click new button on newly opened window and paste your Jre folder link(Jre in JDK) click okey , okey , okey
re run your program :p
re install your java. First check your OS version.
Just simply uninstall java 8 update 45, it worked for me. Also you might need to delete the metadata of your workspace as I have first deleted the metadata and then uninstalled java 8 update 45.
If eclipse (none of them) doesn't launch at all and there's not even an error message, uninstall Java 8 Updater and reinstall Java 8 from scratch, this should work. Have luck!
Try to install Eclipse into a folder without spaces.
Same problem happened with me . I started eclipse after many days , but it was not starting.just eclipse window flashing , no error nothing. After many trials , i just re-installed my jdk . It worked for me, i think some of my java files were missing or damaged . Try by reinstalling your jdk version it may work as it worked for me.
I tried everything except this. After rigorous trials,Uninstalling java 8 update 25 helped me.
did not have to uninstall Java JDK - just ran installer over my existing install. Not sure what was wrong but this fixed my issue with Eclipse not starting.
I had a similar problem with Eclipse mars. It suddenly over the weekend stopped working and if you ran it from a command window (Windows x64) it would flash up a line or two and then stop.
I installed Eclipse neon yesterday and it worked, but today it stopped working and went wrong in the same way.
Just now I installed the JDK from here:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
I installed version 8u101 and then neon started. I have not changed eclipse.ini (although I had a look at it) nor have I deleted the plugins (I renamed the folder and found that this had no effect).
Hence I think this difficult to work out problem relates to the JDK/JRE. It would be nice if Eclipse gave a bit more information to go on, but such is life.
I just had this issue in Eclipse Neon. After trying all these suggestions, it turned out that in my case the problem was improperly configured path variables.
There is a pretty good answer already posted here which explains it, but I'll summarize it in this answer for convenience.
You will need to go into your User Environment Variables panel and modify the following values:
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_102
JDK_HOME : %JAVA_HOME%
JRE_HOME : %JAVA_HOME%\jre
CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
PATH : your-unique-entries;%JAVA_HOME%\bin (make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.
In my case the problem was not having a proper javabin folder in the PATH variable.
Open the PATH variable and make sure it points to a proper JRE bin folder.
Same thing happened to me.
I was using dual monitor and eclipse opened on my other screen, behind a full-screen window.
I have fixed it by deleting the .metadata/.lock file.
In my case I did see the splash screen hanging at
loading org.eclipse.egit.ui
So I deleted everything starting with org.eclipse.egit within the eclipse\plugin folder
Reinstalling eclipse (newer version) did the trick for me.
Seems to be rare but this happens on windows 10 where the eclipse.exe file is located in a sub-folder which has some UTF-8 folder parent
For example this :
D:\Personal\Idea\دستیار هوشمند بانکی\eclipse doesn't work while
D:\Personal\Idea\Bank AI Assistants\eclipse works.
In my case, moving eclipse to a new fresh machine, I had wrong path of lombok.jar in eclipse.ini
check all eclipse.ini configurations
In System Environment variables , add jdk path in the BEGINNING of the Path
.

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.

Categories