简体   繁体   English

为什么我的 ImageView 可以在 Windows 上运行,而不能在 Mac 上运行

[英]Why does my ImageView work on Windows but not on Mac

Here is the simple code for javafx in intellij:这是intellij中javafx的简单代码:

Image image = new Image(url);
ImageView imageView = new ImageView(image);
movieBox.getChildren().add(imageView);

//checking
System.out.println(imageView.getImage().getUrl());
Textfield tx = new Textfield();
tx.setText("hi");
movieBox.getChildren().add(tx);

I copied the project over to intellij on my mac and everything works accept the images won't show.我将项目复制到我的 mac 上的 intellij,一切正常,图像不会显示。 Here are the things I tried:以下是我尝试过的事情:

  • Checking that the URL is valid by printing out the imageview image url.通过打印出 imageview 图像 url 来检查 URL 是否有效。 It prints out a valid URL of an image i can open in my browswer它打印出我可以在浏览器中打开的图像的有效 URL
  • Adding a random textfield to the movieBox (a flowpane object) to make sure it works.向 movieBox(流窗格对象)添加一个随机文本字段以确保其正常工作。 And it does.确实如此。

There shouldn't be any error in the code because it works in my windows intellij.代码中不应该有任何错误,因为它在我的 windows intellij 中工作。 It seems like a problem with the environment, but I haven't even got a clue how should i approach this problem.这似乎是环境问题,但我什至不知道我应该如何解决这个问题。 Any sort of advice will be nice, thanks!任何形式的建议都会很好,谢谢!

Try downloading the image and using the path to the image on your disk, if it works then the problem will be with the url, otherwise its with the ImageView.尝试下载图像并使用磁盘上图像的路径,如果有效,则问题出在 url 上,否则出在 ImageView 上。 If the problem is with the URL, post the one you are trying to use so the community can test it, and try another URL.如果问题出在 URL 上,请发布您尝试使用的 URL,以便社区可以对其进行测试,然后尝试另一个 URL。

PS If you aren't manipulating the image you can just pass the path/url directly top the ImageView constructor. PS 如果您不操作图像,您可以直接将路径/url 传递到 ImageView 构造函数的顶部。

public ImageView(String url)公共图像视图(字符串网址)
Allocates a new ImageView object with image loaded from the specified URL.分配一个新的 ImageView 对象,其中包含从指定 URL 加载的图像。
The new ImageView(url) has the same effect as new ImageView(new Image(url)). new ImageView(url) 与 new ImageView(new Image(url)) 具有相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM