首页 > 解决方案 > 关于创建简单教程和启动的 Nullpointer

问题描述

我正在尝试开始使用代码一,但你好世界开箱即用失败......

我所做的只是在 jdk 11 中创建 Hello World (Bare Bones),我在这条线上得到了一个 Nullpointer..

    final Label apple = new Label(theme.getImage("apple-icon.png")); 

“主题”在 init() 方法中初始化。较新版本的 codeones 是否不调用 init 使 hello world 示例无用?

当我尝试在 jdk 11 中调试时,它在 Intellij 中失败(请注意,如果需要,它会显示确切的 jdk11 版本)。正因为如此,还不知道如何记录,我无法进一步调试问题。

    /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53436,suspend=y,server=n -Xms128m -Xmx2048m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -XX:CICompilerCount=2 -Dsun.io.useCanonPrefixCache=false -Djava.net.preferIPv4Stack=true -Djdk.http.auth.tunneling.disabledSchemes=\"\" -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Djdk.attach.allowAttachSelf=true -Dkotlinx.coroutines.debug=off -Djdk.module.illegalAccess.silent=true -XX:+UseCompressedOops -Dfile.encoding=UTF-8 -XX:ErrorFile=$USER_HOME/java_error_in_idea_%p.log -XX:HeapDumpPath=$USER_HOME/java_error_in_idea.hprof -Dapple.laf.useScreenMenuBar=true -javaagent:/Users/dean/Library/Caches/IdeaIC2019.3/captureAgent/debugger-agent.jar -classpath "/Users/dean/workspace/keepInTouch/out/production/keepInTouch:/Users/dean/workspace/keepInTouch/src:/Users/dean/workspace/keepInTouch/lib/CodenameOne.jar:/Users/dean/workspace/keepInTouch/JavaSE.jar:native/internal_tmp:lib/impl/cls:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar" com.codename1.impl.javase.Simulator com.kit.phone.MyKit
    Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
            Connected to the target VM, address: '127.0.0.1:53436', transport: 'socket'
    JavaFX Not loaded.  Classpath=/Users/dean/workspace/keepInTouch/out/production/keepInTouch:/Users/dean/workspace/keepInTouch/src:/Users/dean/workspace/keepInTouch/lib/CodenameOne.jar:/Users/dean/workspace/keepInTouch/JavaSE.jar:native/internal_tmp:lib/impl/cls:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar . Adding to classpath
    Adding JavaFX to your project properties file at nbproject/project.properties
    JavaFX should be correctly loaded the next time you run this project.
            Restarting JVM with JavaFX in the classpath.
    NOTE: If you are trying to debug the project, you'll need to cancel this run and try running debug on the project again.  JavaFX should now be in your classpath.
    Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
            ERROR: transport error 202: connect failed: Connection refused
    ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
    JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [:732]
    Disconnected from the target VM, address: '127.0.0.1:53436', transport: 'socket'

标签: javafxcodenameone

解决方案


Oracle 从 JDK 9 及更高版本中删除了 Java FX。因此,如果您使用没有它的 JDK 11,您会在调试器中收到该错误。

尝试在调试器之外运行(常规运行)。它将隐式下载 JavaFX 并自行修复。然后杀死虚拟机并再次运行。请注意,您必须有 Internet 连接才能运行此操作,以便我们可以下载与您的 VM 匹配的 JavaFX 库。

还要确保您的插件是最新的。

注意:我们将 Java FX 用于其他地方不可用的浏览器和媒体功能。这仅在模拟器中使用,而不在设备中使用。这种情况下的故障是模拟器的故障,而不是代号一的故障。


推荐阅读