JavaFX imports and extends application not getting recognized - java

I'm having an issue with my JavaFX imports and the extends application portion of my main method.
I've tried cycling through all the SDK and programming level features on my IntelliJ and still no luck
Screenshot of the issue on IntelliJ
Sorry for the low-quality image but any help on this would be greatly appreciated

It seems the javafx library is not added to your classpath. This can be done by adding the folloging to your VM options:
--module-path [path\to\your\javafx\home\lib] --add-modules ALL-MODULE-PATH
where [path\to\your\javafx\home\lib] must point to the location where you downloaded javafx as it does not come with the jdk as of version 11: download
You can also add it as an external library in IntelliJ within the module settings (Dependencies).

If you hover the mouse over one of the red marks on the right-hand size, it should tell you what's wrong with the import. It seems that the IDE is complaining about all your javafx imports, but the other java imports are fine, so my guess is that you are using a JDK version that does not include JavaFX. If that is the case, you need to add it as an extrernal library to your project.
To do that, click on File->Project Structure, then select Libraries, click on the "+" icon, browse to the "lib" sub-folder of the JavaFX SDK folder, and add it.

Related

JavaFX Eclipse suggestion to import not present

I am just starting with JavaFX and for some reason, Eclipse does not suggest to import JavaFX stuff so I have to type it in manually. Example: javafx.scene.Group I typed in Group as a type and it suggested other things such as javax.swing.GroupLayout.Group
image of suggestions
I'm not exactly sure, but I think maybe the fact that the JavaFX library is under Modulepath instead of Classpath has to do with it, but it only works if it is under Modulepath.
Help would be greatly appreciated, thanks!
I'm rewriting this answer, as #kleopatra pointed out it was inexact
For suggestions to work, you need to have JavaFX on your project's build path.
If you've created a plain Java project in Eclipse, with a module-info.java at it's source path root, then you need to add all the required jars to the module path:
JavaFX SDK should already be installed on your system, or download it from Gluon and unzip it
Right-click your Java project, got to Build Path -> Configure Build Path...
Go to Libraries tab, point to the Modulepath section
Click [Add External JARs...] button, pick all the jars from JavaFX SDK, hit [Apply and close]
Then suggestions should work as expected, and imports will be automatically inserted at the top of your java files, but they will appear in error the first time you import anything from a given library module, as this module must also be required in your module-info.java. You can do that automatically with a quick fix ("Add 'requires javafx.something' to module-info.java") when hovering the import.
Now there's a more straightforward way to create a JavaFX modular project in Eclipse, using Maven:
Create a new Maven Project
Check and pass the first wizard screen
Select archetype org.openjfx:javafx-archetype-fxml
On the next screen, you can select the JavaFX version of your choice (currently 13 by default)
After the wizard terminates, you've got a nice little project already setup with an application window and two FXML sample displays. You can start from there to build your own project.

Issue with JavaFX file in Intellij

I'm fairly new to using JavaFX and have been tinkering with it on my own in a few simple projects.
I have to collaborate with a few others for a main project, where I am seeing this conflicting issue:
I'm having an issue with the src.zip file of javafx. On my standalone projects, I do not encounter this issue. However, since working with others, this error has appeared. Prior to this, I was getting a Kotlin plugin issue, where I had to completely disable Kotlin.
Error:java: C:\Users\nolan\Javalibs\javafx-sdk-11.0.2\lib\src.zip
I'm unsure of what this issue might mean, so any help would be appreciated.
Thank you.
I had the same problem too and discovered it was because I added the JavaFX 11 SDK to Intellij incorrectly. I initially had the added library point to just the directory /lib. Since this directory includes both the jars and src.zip, Intellij will try to run both and produce the error.
To solve this, when Intellij prompts you to "Select Library Files," you need to explicitly select the files within the /lib directory which will then be added as shown here. This will also allow proper inspection of the source code without Intellij having to decompile the class file when ctrl + left clicking a class name.
Figured this out. I extracted the src.zip in the appropriate directory (deleting the zip as well), then had to change my VM Path to include:
--module-path "C:\yourpathto\javafx-sdk-11.0.2\lib;out\production" --add-modules=javafx.controls,javafx.fxml
I forgot to add ;out\production to the Module path.
A quick rebuild then solved this issue.

IntelliJ IDEA - "Imported project refers to unknown jdks JavaSE-1.8" while import Eclipse projects

I tried to import Eclipse project to IntelliJ IDEA, but I got this error:
The eclipse project description contains a reference to a "manually" defined JDK (named JavaSE-1.8).
Just go forward and define an SDK for your project within IntelliJ yourself. See here for the necessary steps:
To define a JDK and a mobile SDK in IntelliJ IDEA
Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
In the leftmost pane, under Platform Settings, click SDKs.
Above the pane to the right, click  and select JDK.
In the dialog that opens, select the installation directory of the JDK to be used and click OK.
... (obviously you don't need the Java ME mobile specific things listed in the original link)
Here they had a similar problem, but with android sdk
You must edit Project SDK in Project Structures > Dependencies to existing Java JDK

Android app project in eclipse has many package errors, how do I fix this?

I was working on an app about a year ago, and kinda forgot about it for some time. I want to get back into it, but every import has an error. I feel like I am just forgetting something simple, but I dont know what it is.
standard java projects (non-android) work fine, but anything android related has errors. I tried updating to the newest sdk (23.0.2), but that did not fix the problems.
here is a screenshot of what is going on.
Edit: I also just insalled the newest build tools, and all the extras in the android sdk manager. This did not fix the problem.
edit 2: It seems that if I go to the Library build paths, the JRE System Library can't be added. If I added, the name of it changes to "Unable to get system library for this project" This only happens with android projects, and not with non-android projects.
Final edit: the problem was fixed by changing the android target version
The following steps could help:
Right-click on project » Properties » Java Build Path
Select Libraries tab
Find the JRE System Library and remove it
Click Add Library... button at right side » Add the JRE System Library (Workspace default JRE)
After this clean your project.

android-support-v4.jar isn't importing correctly in Eclipse

I'm trying to get an app to compile that uses the android-support-v4.jar and the Fragmentation classes it contains, but I keep getting messages whenever I try to compile that there are errors in the code. All of the errors have to do with different Fragmentation classes that are in the .JAR. I have tried ctrl-clicking the project folder and then selecting Android Tools -> Add Compatibility Library and I keep getting this error:
[2011-12-20 11:55:31 - Android Compatibility JAR not found:]
/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar
Why would it be looking for the .JAR in Eclipse's Package Contents? I've gone into the project properties and went to the Java Build Path, and imported the .JAR from the MainActivity/libs folder, that didn't work, and then I tried to import it from my SDK directory, and that didn't work. I've fixed the project properties and cleaned and built it countless times, I've restarted Eclipse, my computer, re-downloaded and installed Eclipse, the Android SDK's and ADT and still nothing. I am completely stumped.
Edit
I've gone through the build path and imported the .JAR from both the MainActivity/libs and my SDK directory. For the hell of it I added the .JAR in the directory that keeps appearing in the errors and that hasn't worked. What's making Eclipse look for it in it's Application Package Contents?
Update
So after tinkering the project contents aren't showing any errors but the MainActivity folder still says that there is one and I still can't compile.
Like nyah:
Revision
So I think the question may be "Why is Eclipse looking for the .JAR in the Eclipse Application's package contents instead of the libs directory of the project or the Android SDK directory that I used to import it as an external .JAR?"
Update #2
I am only getting one error now after tinkering, it's on this method:
#Override
public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
// Noop
return this;
}
The Quick Fix says that I should delete the #Override annotation but that method must override a super class method.
These are the errors that it shows:
Multiple markers at this line
- The method setOnActionExpandListener(MenuItem.OnActionExpandListener) of type SimpleMenuItem must override a superclass method
- implements android.view.MenuItem.setOnActionExpandListener
Looks like it is looking for jar here :/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar
android-support-v4.jar is found in <sdk>/extras/android/compatibility/v4
Please make sure you add this as an external jar in the java build path
I could solve this problem by
1- delete "android-support-v4.jar" from lib
2- right click on the name of the project choose "Android Tools" and "Add Support Library"
If this is still not solved:
Like already said, in Eclipse go to your Project Properties > Java Build Path > Libs > Add External and get the one from the adk directory.
Also set up Java 1.6 as your default compile version if you already haven't. This should solve the Override Errors you described.
It turns out that my Debug Certificate had expired so I just needed to delete ~/.android/debug.keystore and restart Eclipse and everything worked.
I realize that this question has been answered, but this is a known issue that is supposed to be fixed in the ADT-17 plugin release according to comment 9 here: http://code.google.com/p/android/issues/detail?id=21488
In addition, people who have this problem can copy the compatibility JAR to the location it says it can't find it. Clearly it's looking in the wrong place (since it's checking the Eclipse directory rather than the android-sdk directory), so the simple fix, for now, is simply to put the package where it wants to find it, even though it doesn't belong.
For me it was as simple as copying the v4 directory within C:/android-sdk/extras/android/support/ into the C:/eclipse/ directory.
I had the same problem running in Ubuntu. Go to Tools->Options.
Check Force https://... to http://
Open Android SDK Manager. Check Extras->Android Support Library.
Something similar happened to me. At the top of MainActivity.java I had the next imports giving errors:
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
In each of the lines on the left they had the light bulb making some suggestions. If you click on it, one of the options will be "Fix project setup". You then will be able to choose between several options for fixing the imports, you should choose the one that specifies the android-support-v4.jar.
Right click on ur project --> select android tools --> select add support library and simply installed the supporting libraries.
Do you try not to do Android Tools -> Add Compatibility Library, and only add the jar in java build path library?.
I use this jar library of this way and it works without any problem.
I had the same problem.
Under the project properties:Java Build Path:Order and Export tab, the box next to android-support-v4.jar wasn't checked. I checked the box, and the error went away.
Another caveat was running Android SDK Manager in Windows 7 without administrator privileges. It would try to install support package, but would always fail, and the actual package never got downloaded to
C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4\android-support-v4.jar
Solution: Make sure that you enter the same API for "Target SDK" and "Compile with" during Android project creation (or in the Manifest file once created).

Categories