【问题标题】:Setting ImageView Image results in error设置 ImageView Image 会导致错误
【发布时间】:2015-12-16 18:41:01
【问题描述】:

我正在尝试设置Image 对象的Image。我的代码:

Image photo = new Image("http://example.com/image.jpg", 100, 0, false, false);
ImageView face = new ImageView();
face.setImage(photo);

我在第 2 行和第 3 行遇到错误,但我非常关注 the documentation。 文档摘录:

// load the image
Image image = new Image("flower.png");

// simple displays ImageView the image as is
ImageView iv1 = new ImageView();
iv1.setImage(image);

错误

第 2 行:

java: constructor ImageView in class javax.swing.text.html.ImageView cannot be applied to given types;
  required: javax.swing.text.Element
  found: no arguments
  reason: actual and formal argument lists differ in length

第 3 行:

java: cannot find symbol
  symbol:   method setImage(javafx.scene.image.Image)
  location: variable face of type javax.swing.text.html.ImageView

【问题讨论】:

  • 您可以将错误添加到您的问题中吗?
  • 编译错误还是运行时错误?如果是编译错误,请包含您的导入。

标签: java image javafx javafx-8


【解决方案1】:

您有错误的导入。你需要

import javafx.scene.image.ImageView ;

您已导入javax.swing.text.html.ImageView。

【讨论】:

  • 哇!非常感谢,我遇到了同样的问题=)
猜你喜欢
  • 2016-07-05
  • 2013-02-14
  • 1970-01-01
  • 2011-06-05
  • 2023-03-05
  • 1970-01-01
  • 2012-05-02
  • 2019-08-18
  • 2017-01-31
相关资源
最近更新 更多