0

I would like to use JavaFX for my game's start screen.

However, for some reason, the import "javafx" does not seem to be recognized.

enter image description here

At first, I (for some weird reason) thought I needed e(fx)clipse, however I successfully installed that and it does not fix the issue. I have found nothing else on the internet that fixes the issue.

Do I need to import javafx as a library or something? And if so, where?

Thanks!

Joehot200
  • 1,070
  • 15
  • 44

3 Answers3

2

Even in Java7, the javafx jar is included, but not in the classpath by default (you need java8 for that).

So, you could just copy the jfxrt.jar from your java installation's /lib directory into your local project's includes, and add it to the classpath there (ie. java -cp .*:lib/*)

SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
  • There is no "javafx.jar" or "jfxrt.jar" in "/lib". http://gyazo.com/37e146c01fe26ecc8ec778ccb97f06e6 – Joehot200 Sep 16 '14 at 14:51
  • @Joehot200 and it's called `jfxrt.jar` – SnakeDoc Sep 16 '14 at 15:18
  • @Joehot200 on my test vm here, it's under: `C:\Program Files\Java\jre7\lib\jfxrt.jar` -- so the regular jre directory... but the exact location may depend on your java7 version... javafx is/was considered experimental under java7. – SnakeDoc Sep 16 '14 at 15:22
  • I keep getting "RenderJob.run: internal exception" when I try to run the code? Whole error: http://pastebin.com/ntPAqp5p – Joehot200 Sep 16 '14 at 16:33
  • @Joehot200 It could be a few things. JavaFX changed forms many times in java7, so even different versions of the jfxrt.jar might cause exceptions (the interfaces/api's changed, etc... still compile, but might blow up at runtime, etc). When I did this last, I found that java7_45 and lower worked, but any higher and the jfxrt.jar had some changed api's, and caused something similar in my app. You could try installing an older version of java7, then just grab it's jfxrt.jar and try using it instead of the one you have now. – SnakeDoc Sep 16 '14 at 16:43
  • @Joehot200 if this is a new project, it might be beneficial to just move to java8 for this... since the javafx api's have been stabilized and are more-or-less final in java8. you can always compile to target java7 so it will run on j7 machines (just make sure to avoid any java8-specific features like lambdas etc.) – SnakeDoc Sep 16 '14 at 16:52
  • But what if I want the game to run on java 7 or java 6? Really, I think that this is so new that it is not practical for me to use it in a public game which I want almost any noob to be able to run. – Joehot200 Sep 17 '14 at 10:01
  • @Joehot200 have you considered bundling the jre with your game? Look into Install4j and exec4j. There are others like AdvancedInstaller, etc that are free. This way you can guarantee your app will run on the expected jre. if you leave it up to the users, things might look funny or not render correct depending on the jre version, etc. (also, java6 is far EOL'd... ) – SnakeDoc Sep 17 '14 at 15:15
1

You might probably missing right version jdk in your classpath.

above JDK 7u6 versions have JavaFX included with the standard JDK and JRE bundles so you can download it from Oracle website. Here is the link:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

DeepInJava
  • 1,871
  • 3
  • 16
  • 31
  • Ok, thanks.... So wait, what do I do after I download that JDK? What is this classpath you mean and how do I add it to the classpath? Sorry for being an idiot. xD – Joehot200 Sep 16 '14 at 14:31
  • its ok that you dont know the classpath, i mean to say download above jdk7u6 version and point your project to this jdk and it will work for you. You can refer below youtube link: https://www.youtube.com/watch?v=EEcpMTpaWhs – DeepInJava Sep 16 '14 at 14:35
1

I found the solution to this problem. Please refer and download the jdk 1.8 and installed.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33