当前位置:编程学习 > JAVA >>

javafx基础问题

其实我对javafx一点都不懂,连搭建环境都不会。我下了javafx的安装包,里面有一推jar和配置文件,我专门下了javafx的jar,网上找的,不知道对不对,反正jar导进去后

import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;

这些玩意就都找到了,下面没有红线了,但是运行后,说找不到glass.dll,
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: E:\Temp\q\bin\glass.dll
然后我在javafx的安装目录下还真找到了这个glass。dll坑爹的是有报了这玩意
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodError: reportException
这是什么情况啊, --------------------编程问答-------------------- 我建议你先网上搜搜教程再问这么难的问题吧。。 --------------------编程问答-------------------- 为什么我发的帖子总是没人回 --------------------编程问答--------------------
引用 2 楼 aaaabbbccd9876 的回复:
为什么我发的帖子总是没人回


main贴出来来看下。那个是调用了未定义的方法 --------------------编程问答--------------------
引用 3 楼 huxiweng 的回复:
Quote: 引用 2 楼 aaaabbbccd9876 的回复:

为什么我发的帖子总是没人回


main贴出来来看下。那个是调用了未定义的方法


public static void main(String arg[]) {
fianal.launch(arg);
}

报的错误:


Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fianal
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at fianal.<init>(fianal.java:63)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Ball.<clinit>(Ball.java:16)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
... 12 more

--------------------编程问答--------------------
引用 4 楼 aaaabbbccd9876 的回复:
Quote: 引用 3 楼 huxiweng 的回复:

Quote: 引用 2 楼 aaaabbbccd9876 的回复:

为什么我发的帖子总是没人回


main贴出来来看下。那个是调用了未定义的方法


public static void main(String arg[]) {
fianal.launch(arg);
}

报的错误:


Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fianal
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at fianal.<init>(fianal.java:63)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Ball.<clinit>(Ball.java:16)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
... 12 more


可以正常运行了,但是打包出错了,

init-fx-tasks:
  [taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:

BUILD FAILED
C:\Users\Administrator\Desktop\build.xml:87: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet


求大神指示 --------------------编程问答-------------------- heh 大神不敢当,但是这确实是fx初学者常遇到的问题:缺少glass。dll是因为你没有fx的runtime,而仅仅只是导入乐jfxrt.jar,是吗,然而javafx不仅仅只是jfxrt.jar哦。不能作为普通的jar来看待。之前是有专门的JavaFX SDK下载的还需安装(jdk6),后来jdk7内部集成了javafx。所以你只要下载jdk7就自动包含了fx2.2,如果你想体验更强大的javafx功能,就去下载jdk8,里面自动包含了javafx 8。
至于使用如果是命令行环境,则需包含fxrt.jar的路径就可以了,打包成jar时要用java deployment toolkit,不能用普通的eclipse的打包工具。
如果是eclipse下的环境:导入fxrt.jar。可以下载e(fx)clipse插件,是对javafx的支持。
如果是netbeans的话,自动支持了javafx2.2的应用程序开发,打包的话也像原来那样用netbeans就可以了。
如果是idea的话,自动支持到了JDK8+javafx8, 所以也不需导入fxrt.jar和另外学习javafx的打包了。 --------------------编程问答-------------------- 如果是运行fx程序没问题,打包有问题的。我有一个完整的打包例子:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:fx="javafx:com.sun.javafx.tools.ant" default="main">
    <!-- Import definition of JavaFX ant tasks, be attention to the path of JDK installed -->
    <taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant"
             classpath="/home/gaowen/jdk1.7.0_45/lib/ant-javafx.jar"/>
    <property name="application.title" value="EnterprisePurchaseSellStockManagementSystem"/>
    <property name="application.vendor" value="Gaowen HAN"/>
    <property name="application.version" value="2.0"/>
    <property name="src" value="src"/>
    <property name="compile" value="bin"/>
    <property name="dist" value="dist"/>
    <property name="web" value="web"/>
    <property name="javafx" value="${java.home}/lib/jfxrt.jar"/>
    <property name="preloader" value="dist/lib/EnterprisePurchaseSellStockManagementSystemPreloader.jar"/>
    <property name="derbynet" value="dist/lib/derbynet.jar"/>
    <splash showduration="0" imageurl="file://${user.dir}/ant-splash.jpg"
            displayText="${application.vendor}-${application.version}: Building..." progressRegExp="Progress: (.*)%"/>
    <sound>
        <success source="bell.wav" loops="0"/>
        <fail source="ohno.wav" loops="0"/>
    </sound>
    <target name="init">
        <echo message="I am target 'init'" level="info"/>
        <mkdir dir="${compile}"/>
        <javac srcdir="${src}" destdir="${compile}" includeAntRuntime="false"
               classpath="${javafx}; ${preloader}; ${derbynet}"/>
        <copy todir="${compile}">
            <fileset dir="${src}" excludes="**/*.java"/>
        </copy>
        <fx:csstobin outdir="${compile}">
            <fileset dir="${compile}" includes="**/*.css"/>
        </fx:csstobin>
        <!-- Details about application, as id cannot be the escaped string, we assign it by abbreviation of ${application.title} -->
        <fx:application id="epssms" name="${application.title}" version="${application.version}"
                        mainClass="epssms.MainFrame" preloaderClass="epssmspreloader.EPSSMSPreloader">
            <fx:param name="language" value="en"/>
            <fx:param name="country" value="US"/>
        </fx:application>
        <!-- Define what classpath to use, all resources will be recopied to the position sepecified by "includes" under the folder "${dist}" -->
        <fx:resources id="appRes">
            <fx:fileset id="preloader-files" dir="${dist}" type="jar" requiredFor="preloader"
                        includes="lib/EnterprisePurchaseSellStockManagementSystemPreloader.jar"/>
            <fx:fileset id="derbyclient" dir="${dist}" type="jar" includes="lib/derbyclient.jar"/>
            <fx:fileset id="derbynet" dir="${dist}" type="jar" includes="lib/derbynet.jar"/>
            <fx:fileset id="derby" dir="${dist}" type="jar" includes="lib/derby.jar"/>
            <fx:fileset dir="${dist}" type="jar" includes="${application.title}.jar"/>
        </fx:resources>
        <echo message="Progress: 20%" level="info"/>
    </target>
    <target name="jar" depends="init">
        <echo message="I am target 'jar'" level="info"/>
        <fx:jar destfile="${dist}/${application.title}.jar">
            <fx:application refid="epssms"/>
            <fx:resources>
                <fx:fileset refid="preloader-files"/>
                <fx:fileset refid="derbyclient"/>
                <fx:fileset refid="derbynet"/>
                <fx:fileset refid="derby"/>
            </fx:resources>
            <!-- What to include into result jar file? -->
            <fx:fileset dir="${compile}" includes="**/*" excludes="**/*.css"/>
            <!-- Customize jar manifest (optional) -->
            <manifest>
                <attribute name="Implementation-Vendor" value="${application.vendor}"/>
                <attribute name="Implementation-Title" value="${application.title}"/>
                <attribute name="Implementation-Version" value="${application.version}"/>
                <attribute name="SplashScreen-Image" value="splash.jpg"/>
                <attribute name="Permissions" value="all-permissions"/>
                <attribute name="Codebase" value="*"/>
            </manifest>
        </fx:jar>
        <echo message="Progress: 25%" level="info"/>
    </target>
    <target name="keystore.check">
        <echo message="I am target 'keystore.check'" level="info"/>
        <condition property="keystore.exist">
            <and>
                <available file="${application.vendor}-Keystore"/>
            </and>
        </condition>
        <echo message="Progress: 30%" level="info"/>
    </target>
    <!-- For generating keys, see http://docs.oracle.com/javase/tutorial/security/toolsign/step3.html -->
    <target name="genkey" depends="jar, keystore.check" unless="keystore.exist">
        <echo message="I am target 'genkey'" level="info"/>
        <genkey verbose="false" validity="90" alias="javafx" storepass="212188" keypass="881212"
                keystore="${application.vendor}-Keystore">
            <dname>
                <param name="CN" value="${application.vendor}"/>
                <param name="OU" value="${application.vendor}"/>
                <param name="O" value="${application.vendor}"/>
                <param name="L" value="wuhan"/>
                <param name="ST" value="hubei"/>
                <param name="C" value="CN"/>
            </dname>
        </genkey>
        <echo message="Progress: 35%" level="info"/>
    </target>
    <target name="signjar" depends="genkey">
        <echo message="I am target 'signjar'" level="info"/>
        <fx:signjar verbose="false" destdir="${dist}" alias="javafx" keypass="881212"
                    keystore="${application.vendor}-Keystore" storepass="212188">
            <fx:fileset dir="${dist}" includes="${application.title}.jar"/>
            <fx:fileset dir="${dist}" includes="lib/*.jar"/>
        </fx:signjar>
        <echo message="Progress: 70%" level="info"/>
    </target>
    <target name="deploy" depends="signjar" description="Deploying JavaFX Applications (RIA-Web)">
        <echo message="I am target 'deploy'" level="info"/>
        <fx:deploy verbose="false" offlineAllowed="false" width="600" height="400" embeddedWidth="100%"
                   embeddedHeight="100%" embedJNLP="true" outdir="${dist}" outfile="${application.title}">
            <fx:application refid="epssms"/>
            <fx:resources refid="appRes"/>
            <fx:info category="${application.title}" license="GPL" copyright="by ${application.vendor}"
                     description="It is ${application.title}." title="${application.title}"
                     vendor="${application.vendor}"/>
            <fx:template file="${web}/index_template.html" tofile="${dist}/${application.title}.html"/>
            <fx:callbacks>
                <fx:callback name="onGetSplash">getSplash</fx:callback>
            </fx:callbacks>
            <!-- Request elevated permissions which requires signing all JAR files related to application (including the application jar itself). It requires also that the application does not run in the sandbox -->
            <fx:permissions elevated="true" cacheCertificates="true"/>
        </fx:deploy>
        <echo message="Progress: 90%" level="info"/>
    </target>
    <target name="main" depends="deploy">
        <echo message="I am target 'main'" level="info"/>
        <java jar="${dist}/${application.title}.jar" fork="true"/>
        <echo message="Progress: 100%" level="info"/>
    </target>
</project>

这个是用来打包企业进销存管理系统的。
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,