javafx基础问题

aaaabbbccd9876 2013-12-19 10:51:58
其实我对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
这是什么情况啊,
...全文
3987 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
捏造的信仰 2015-11-12
  • 打赏
  • 举报
回复
引用 9 楼 u013025830 的回复:
bin下面有一堆dll,你没有,不光是jar,还要有这些dll
兄弟你为何要挖坟?
soton_dolphin 2015-11-11
  • 打赏
  • 举报
回复
给你这个网站吧,适合初学者
wjyjz 2015-11-11
  • 打赏
  • 举报
回复
我照猫画虎做了一个javafx项目,想看看开头对不对,果然不对,请各位高手指点: Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at hrms.controller.HrmsMainApp.initrootLayout(HrmsMainApp.java:26) at hrms.controller.HrmsMainApp.start(HrmsMainApp.java:19) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) ... 1 more Exception running application hrms.controller.HrmsMainApp 下面我给出我的项目主程序HrmsMainApp.java文件

package hrms.controller;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class HrmsMainApp extends Application {
	private Stage primaryStage;
	private BorderPane rootLayout;

	@Override
	public void start(Stage primaryStage) {
		this.primaryStage = primaryStage;
		this.primaryStage.setTitle("������Դ����ϵͳ");
		initrootLayout();
	}

	public void initrootLayout() {
		try {
			FXMLLoader loader = new FXMLLoader();
			loader.setLocation(HrmsMainApp.class.getResource("hrms.view/RootLayout.fxml"));
			rootLayout = (BorderPane) loader.load();
			// Show the scene containing the root layout.
			Scene scene = new Scene(rootLayout);
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public Stage getPrimaryStage() {
		return primaryStage;
	}

	public static void main(String[] args) {
		launch(args);
	}
}
还有RootLayout.fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>

<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" type="BorderPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <top>
      <HBox alignment="BOTTOM_RIGHT" depthTest="ENABLE" prefHeight="80.0" prefWidth="1280.0" style="-fx-background-color: #336699;" BorderPane.alignment="CENTER">
         <children>
            <Button mnemonicParsing="false" text="Button">
               <HBox.margin>
                  <Insets bottom="6.0" right="100.0" />
               </HBox.margin>
            </Button>
            <Button contentDisplay="CENTER" mnemonicParsing="false" text="Button">
               <HBox.margin>
                  <Insets bottom="6.0" right="100.0" />
               </HBox.margin>
            </Button>
         </children></HBox>
   </top>
   <left>
      <Accordion BorderPane.alignment="CENTER">
        <panes>
          <TitledPane animated="false" text="untitled 1">
               <content>
                  <SplitPane prefHeight="200.0" prefWidth="200.0" />
               </content>
               <padding>
                  <Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
               </padding>
            </TitledPane>
          <TitledPane animated="false" text="untitled 2">
               <content>
                  <SplitPane prefHeight="200.0" prefWidth="200.0" />
               </content>
            </TitledPane>
        </panes>
      </Accordion>
   </left>
   <bottom>
      <HBox prefHeight="40.0" prefWidth="1280.0" BorderPane.alignment="CENTER" />
   </bottom>
   <center>
      <Pane BorderPane.alignment="CENTER">
         <BorderPane.margin>
            <Insets bottom="3.0" left="3.0" top="3.0" />
         </BorderPane.margin></Pane>
   </center>
</fx:root>
重点是我做的哪里不对,主文件中19和26行怎么做才对?我是初学者,麻烦指点详细一点!!!
  • 打赏
  • 举报
回复
bin下面有一堆dll,你没有,不光是jar,还要有这些dll
QQ2472322319 2014-06-02
  • 打赏
  • 举报
回复
引用 4 楼 aaaabbbccd9876 的回复:
[quote=引用 3 楼 huxiweng 的回复:] [quote=引用 2 楼 aaaabbbccd9876 的回复:] 为什么我发的帖子总是没人回
main贴出来来看下。那个是调用了未定义的方法[/quote]

	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

[/quote] public class XXX extends Application{ ... }
teemai 2013-12-20
  • 打赏
  • 举报
回复
引用 2 楼 aaaabbbccd9876 的回复:
为什么我发的帖子总是没人回
main贴出来来看下。那个是调用了未定义的方法
aaaabbbccd9876 2013-12-20
  • 打赏
  • 举报
回复
为什么我发的帖子总是没人回
fearlessMore 2013-12-20
  • 打赏
  • 举报
回复
如果是运行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>
这个是用来打包企业进销存管理系统的。
fearlessMore 2013-12-20
  • 打赏
  • 举报
回复
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的打包了。
aaaabbbccd9876 2013-12-20
  • 打赏
  • 举报
回复
引用 4 楼 aaaabbbccd9876 的回复:
[quote=引用 3 楼 huxiweng 的回复:] [quote=引用 2 楼 aaaabbbccd9876 的回复:] 为什么我发的帖子总是没人回
main贴出来来看下。那个是调用了未定义的方法[/quote]

	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

[/quote] 可以正常运行了,但是打包出错了,

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

求大神指示
aaaabbbccd9876 2013-12-20
  • 打赏
  • 举报
回复
引用 3 楼 huxiweng 的回复:
[quote=引用 2 楼 aaaabbbccd9876 的回复:] 为什么我发的帖子总是没人回
main贴出来来看下。那个是调用了未定义的方法[/quote]

	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

lcf 2013-12-19
  • 打赏
  • 举报
回复
我建议你先网上搜搜教程再问这么难的问题吧。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧