我正在为 Bindings.when 苦苦挣扎...我试图创建一个百分比分数,当成功测试的数量发生变化(在下面的代码中反映为“successCountProperty”)或测试总数发生变化时(反映在“结果”的 sizeProperty 中)。当我执行这段代码时,我得到 java.lang.ArithmeticException: / 为零。当我最初遇到异常时,我找到了 Bindings.when().then().otherwise(),在我的脑海中应该可以解决问题。不幸的是,在执行此代码时,尽管 'when' 返回 false,'then' 仍在执行。任何人都可以帮忙吗?
public void foo()
{
DoubleProperty scoreProperty = new SimpleDoubleProperty(0);
ListProperty<String> results = new SimpleListProperty<>(FXCollections.observableArrayList());
IntegerProperty successCountProperty = new SimpleIntegerProperty(0);
scoreProperty.bind(Bindings.when(results.sizeProperty().greaterThan(0))
.then(Bindings.divide(successCountProperty, results.sizeProperty())).otherwise(0));
}
Run Code Online (Sandbox Code Playgroud) 我正在升级我们的应用程序以使用 Java 9(婴儿学步......一旦我们让 9 工作,我们将跳到 10)。我们遇到的问题之一是在运行时,我们收到模块异常,而我似乎无法弄清楚发生了什么。诚然,我对模块很陌生,并且已经阅读了我能找到的有关该主题的所有内容,但我猜这可能是一个简单的答案。
调用的运行时间是
java --add-modules java.se,java.se.ee -cp mainjar.jar:jaxb-api.jar:jaxb-impl.jar:jaxb-core.jar foo.bar.Launch
Run Code Online (Sandbox Code Playgroud)
尝试读取 XML 数据时发生异常:
WARN:09:22:10.777 [main] (Preference:969) - Failed to unmarshal preference value for key [launch.maxMemory]: javax.xml.bind.JAXBException: Package java.lang with JAXB class java.lang.Integer defined in a module java.base must be open to at least java.xml.bind module.
javax.xml.bind.JAXBException: Package java.lang with JAXB class java.lang.Integer defined in a module java.base must be open to at least java.xml.bind module.
at java.xml.bind@9.0.4/javax.xml.bind.ModuleUtil.delegateAddOpensToImplModule(Unknown Source)
at java.xml.bind@9.0.4/javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at java.xml.bind@9.0.4/javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at java.xml.bind@9.0.4/javax.xml.bind.ContextFinder.find(Unknown Source) …Run Code Online (Sandbox Code Playgroud) 我正在努力将项目的构建结构从Ant转换为Maven(3.3.3),使用Java 1.8,并遇到了一个令我困扰的问题.我们所有的单元测试都在Ant和Eclipse中正常运行,但是我遇到了几个在Maven中执行时失败的单元测试.该测试失败(不幸的是,我不能发布源由于企业限制),所有人都试图通过javax.imageio.ImageIO中的类来读取图像,似乎都失败了的NoClassDefFoundError,说明他们无法初始化的Java. nio.file.TempFileHelper.现在,我已经看到了这个类型的东西时试图初始化类问题突然出现,和失败(而不是不能够找到类定义的话),但我看着TempFileHelper类的来源,我似乎无法弄清楚会失败的是什么.
堆栈跟踪(手动输入,任何类型的道歉):
java.lang.NoClassDefFoundError: Could not initialize class java.nio.file.TempFileHelper
at java.nio.file.Files.createTempFile(Files.java:897)
at javax.imageio.stream.FileCacheImageInputStream.<init>(FileCacheImageInputStream.java:102)
at com.sun.imageio.spi.InputStreamImageInputStreamSpi.createInputStreamInstance(InputStreamImageInputStreamSpi.java:69)
at javax.imageio.ImageIO.createImageInputStream(ImageIo.java:357)
at javax.imageio.ImageIO.read(ImageIO.java:1397)
... our code beyond here ...
Run Code Online (Sandbox Code Playgroud)
调用ImageIO.read的类是在与单元测试(称为核心)不同的maven模块中定义的,并且在此之前核心已成功构建.调用ImageIO.read的类正在提供指向core中定义的png文件的相对路径,并且该图像存储在核心的resources文件夹中,位于"images"子文件夹下.
例如,使用foo.png作为文件名:
core/src/main/resources/images/foo.png
URL imageUrl = SomeClass.class.getResource("/images/foo.png");
ImageIO.read(imageUrl);
Run Code Online (Sandbox Code Playgroud)
我已经验证了foo.png在核心构建之后位于core.jar中,并且位于jar的根目录之后的images文件夹中,并且核心模块是正在测试的模块的有效依赖项.
任何帮助是极大的赞赏!
在浏览TempFileHelper时,我偶然发现了一些可能失败的代码,并将其带入我的单元测试中,看它是否继续失败.现在失败似乎表明默认文件系统是未知的,通过以下堆栈跟踪:
java.lang.AssertionError: Platform not recognized
at sun.nio.fs.DefaultSystemProvider.create(DefaultSystemProvider.java:68)
... our code truncated...
Run Code Online (Sandbox Code Playgroud)
根据Alexandre Cartapanis的要求,这是POM片段.该项目是多模块的,父pom正在使用插件管理来控制版本.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
<compilerArg>-XDignore.symbol.file</compilerArg> …Run Code Online (Sandbox Code Playgroud) 我在JavaFX标签中遇到了一组非常奇怪的情况,包括文本换行和居中对齐.我确定我做错了什么或者说不明智,但我似乎无法弄清楚我做错了什么.
基本上,我正在尝试将标题放在图块窗格上,并将该标题置于中心位置.此外,当窗口调整大小时,我想要包装标题.当标题没有被包裹时(例如:一行),它就不再是中心了.一旦它包裹起来,它就会再次集中.以下是一些产生效果的示例代码:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.apache.commons.lang.RandomStringUtils;
public class Foo extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
TilePane panel = new TilePane();
panel.setTileAlignment(Pos.CENTER_LEFT);
for (int i = 0; i < 25; i++)
{
panel.getChildren().add(new Label(RandomStringUtils.randomAlphabetic(10)));
}
Label title = new Label("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
title.setStyle("-fx-font-size: 16; -fx-font-weight: bold; -fx-wrap-text:true; -fx-text-alignment: center -fx-border-color:black;");
title.minWidthProperty().bind(Bindings.add(-30, primaryStage.widthProperty()));
title.setTextAlignment(TextAlignment.CENTER);
VBox box = new …Run Code Online (Sandbox Code Playgroud)