无法使用javafx按存储在mysql中的图像路径加载图像

无法使用javafx按存储在mysql中的图像路径加载图像,java,mysql,image,javafx,desktop,Java,Mysql,Image,Javafx,Desktop,下面是我的示例代码。 它使用mysql中存储的剩余图像相对路径加载保存在本地文件夹中的图像,但它说源未知..请帮助 public void LoadTimelineImg()引发SQLException{ String sql=“按id从t\U时间线顺序选择id、img\U url”; 语句SELCOLUMENT=conn.createStatement(); ResultSet ResultSet=selgamentment.executeQuery(sql); while(resultSe

下面是我的示例代码。 它使用mysql中存储的剩余图像相对路径加载保存在本地文件夹中的图像,但它说源未知..请帮助


public void LoadTimelineImg()引发SQLException{
String sql=“按id从t\U时间线顺序选择id、img\U url”;
语句SELCOLUMENT=conn.createStatement();
ResultSet ResultSet=selgamentment.executeQuery(sql);
while(resultSet.next()){
int id=resultSet.getInt(“id”);
ArrayList images=新的ArrayList();
字符串img_path=resultSet.getString(“img_url”);
添加(新图像(“\”“+”/application/images/”+img\u路径+“\”);
时间线=新时间线(新关键帧)(持续时间。秒(5),事件->{
setImage(images.get(count));
计数++;
如果(计数=5){
计数=0;
}
}));
timeline.setCycleCount(timeline.unfinite);
timeline.play();
}
}

图像类构造函数将字符串作为参数。此字符串不能像您提供的字符串那样重复引用

因此,您可以执行以下操作:

String rootPath = "/application/images/"; // or "C:/application/images/" on windows
// assuming img_path = "somefolder1/somefolder2/imagename.ext"
Image img = new Image(rootPath + img_path);


为什么要创建倍增
时间线
?是的,先生,我尝试创建一个图像转换..这些图像在我桌面的某个文件夹中,它通过存储在mysql数据库中的图像路径加载..我不知道我是否理解您的答复。对于结果集中的每个结果,您的代码都在创建一个
时间线
。出现
时间线
,试图每五秒钟更改一次图像。这意味着,如果您的代码返回十个图像,您将有十个
时间线。每次他们各自达到5秒配额时,他们都会尝试更改
ImageView
。这对我来说似乎不合逻辑。有代码建议吗,先生?我有5个图像路径,例如“application/images/img1.jpg”等等。。存储在mysql中。我想从javafx中的mysql加载这些图像路径,以每5秒创建动画更改图像。代码建议您从循环中删除
时间线。我建议您使用一个
数据库处理程序
,只处理数据库操作。您将数据库操作与GUI代码混合使用。是关于如何实现数据库处理程序的想法。
String rootPath = "/application/images/"; // or "C:/application/images/" on windows
// assuming img_path = "somefolder1/somefolder2/imagename.ext"
File file = new File(rootPath, img_path);
Image img = new Image(file.toURI().toURL().toString());