Java 从Mysql读取图像路径

Java 从Mysql读取图像路径,java,imageview,javafx-2,Java,Imageview,Javafx 2,我需要从数据库加载多个图像。为了检索图像路径,我使用以下代码,但我无法在场景中显示图像 c[i] = m_ResultSet.getString(3);// take image path from db for (int j = 0; j < 5; j++) { try { final Image image = images[j] = new Image(c[j]); } catch (NullPointerException e) { }

我需要从数据库加载多个图像。为了检索图像路径,我使用以下代码,但我无法在场景中显示图像

c[i] = m_ResultSet.getString(3);// take image path from db

for (int j = 0; j < 5; j++) {

    try {
        final Image image = images[j] = new Image(c[j]);
    } catch (NullPointerException e) {
    }
    final ImageView pic = pics[j] = new ImageView(images[j]);
    pic.setEffect(shadow);
    pic.setEffect(reflection);

    vb.getChildren().add(pics[j]);

}
c[i]=m_ResultSet.getString(3);//从数据库获取图像路径
对于(int j=0;j<5;j++){
试一试{
最终图像=图像[j]=新图像(c[j]);
}捕获(NullPointerException e){
}
最终图像视图pic=pics[j]=新图像视图(图像[j]);
图.设置效果(阴影);
图.设置效应(反射);
vb.getChildren().add(pics[j]);
}
这样,我在现场看不到任何图像。有没有从数据库读取图像并在现场显示的建议

我解决了这个问题

                for (int j = 0; j < 14; j++) {
        files =c [j];
        File f4 = new File(files);
        try{
        final Image image = images[j] =
            new Image(f4.toURI().toString(), 256, 256, false, false);

        }
        catch(NullPointerException e ){
  }
        final ImageView pic = pics[j] =
            new ImageView(images[j]);
        pic.setEffect(shadow);
        pic.setEffect(reflection);

        vb.getChildren().add(pics[j]);
for(int j=0;j<14;j++){
files=c[j];
文件f4=新文件(个文件);
试一试{
最终图像=图像[j]=
新图像(f4.toURI().toString(),256,256,false,false);
}
捕获(NullPointerException e){
}
最终图像视图pic=pics[j]=
新图像视图(图像[j]);
图.设置效果(阴影);
图.设置效应(反射);
vb.getChildren().add(pics[j]);

类加载器可能无法找到给定URL的图像。由于您没有提供“简短、自包含、正确的示例(SSCCE)”,我现在唯一能为您提供的建议是部分引用
javafx.scene.image.image的API:

// Example code for loading images.

import javafx.scene.image.Image;

// load an image in background, displaying a placeholder while it's loading
// (assuming there's an ImageView node somewhere displaying this image)
// The image is located in default package of the classpath
Image image1 = new Image("/flower.png", true);

// load an image and resize it to 100x150 without preserving its original
// aspect ratio
// The image is located in my.res package of the classpath
Image image2 = new Image("my/res/flower.png", 100, 150, false, false);

// load an image and resize it to width of 100 while preserving its
// original aspect ratio, using faster filtering method
// The image is downloaded from the supplied URL through http protocol
Image image3 = new Image("http://sample.com/res/flower.png", 100, 0, false, false);

// load an image and resize it only in one dimension, to the height of 100 and
// the original width, without preserving original aspect ratio
// The image is located in the current working directory
Image image4 = new Image("file:flower.png", 0, 100, false, false);
将这些示例的URL与您在DB中的URL进行比较,并确认图像的存在

编辑:
如果您正在从localhost读取图像,请尝试

final Image image = images[j] = new Image("file:///" + c[j]);

感谢您的回答:)我的图像路径正确,我正在将图像路径带到数组中,但ı无法使用字符串数组从中读取图像路径。最终图像图像=图像[j]=新图像(c[j]);出于测试目的,请尝试在桌面上加载一个示例图像,例如在其他服务器计算机上,然后直接使用字符串从数据库URL加载图像(跳过从数据库读取)。我解决了以下问题: