简体   繁体   English

设置ImageView图像会导致错误

[英]Setting ImageView Image results in error

I'm trying to set the Image of an ImageView object. 我正在尝试设置ImageView对象的Image My code: 我的代码:

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

I'm getting errors on lines 2 and 3, but I'm following the documentation pretty closely. 我在第2行和第3行出现错误,但是我非常关注文档 Excerpt from documentation: 文档摘录:

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

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

Errors 失误

Line 2: 第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

Line 3: 第3行:

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

You have the wrong imports. 您的进口错误。 You need 你需要

import javafx.scene.image.ImageView ;

You have imported javax.swing.text.html.ImageView . 您已经导入了javax.swing.text.html.ImageView

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

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