简体   繁体   中英

Setting ImageView Image results in error

I'm trying to set the Image of an ImageView object. 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. 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:

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:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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