#inside image javafx what is the correct path

31 messages · Page 1 of 1 (latest)

haughty otter
#

Hey how can i place a photo , when i run this it says invalid url , what is the correct path

plush hawkBOT
#

This post has been reserved for your question.

Hey @haughty otter! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

alpine wigeon
#

Does your book constructor take in a URL?

haughty otter
#

It takes a string

#

Actually im beginner but i just want to use my images im image folder

alpine wigeon
#

Show me your constructor

#

Or rather show me where you are using the image path

haughty otter
#

public class Book {
    private String title;
    private String thumbImage;
    private String largeImage;
    
    public Book(String title, String thumbImage, String largeImage) {
        this.title = title;
        this.thumbImage = thumbImage;
        this.largeImage = largeImage;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getThumbImage() {
        return thumbImage;
    }
    
    public void setThumbImage(String thumbImage) {
        this.thumbImage = thumbImage;
    }
    
    public String getLargeImage() {
        return largeImage;
    }
    
    public void setLargeImage(String largeImage) {
        this.largeImage = largeImage;
    }
    
    @Override
    public String toString() {
        return title;
    }
}```
#

here it is

#

it's written in my homwork all should be String

#

but somehow here the string turned into url , but this doesn't mean it's an image?

alpine wigeon
#

Does the error show you which line it occurred on?

#

I suspect it is somewhere where you are declaring the source of the image

haughty otter
#

i thought im not having the correct path

alpine wigeon
#

Show me coverviewercontroller

haughty otter
#
package application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;


public class CoverViewerController {
    @FXML private ListView<Book> booksListView;
    @FXML private ImageView coverImageView;
    
    private final ObservableList<Book> books = FXCollections.observableArrayList();
    
    public void initialize() {
        books.add(new Book("Android How to Program","/images/small/androidhtp.jpg","/images/large/androidhtp.jpg"));
        books.add(new Book("C How to Program","/images/small/chtp.jpg","/images/large/chtp.jpg"));
        books.add(new Book("C++ How to Program","/images/small/cpphtp.jpg","/images/large/cpphtp.jpg"));
        books.add(new Book("Internet and World Wide Web How to Program","/images/small/iw3htp.jpg","/images/large/iw3htp.jpg"));
        books.add(new Book("Java How to Program","/images/small/jhtp.png","/images/large/jhtp.png"));
        books.add(new Book("Visual Basic How to Program","/images/small/vbhtp.jpg","/images/large/vbhtp.jpg"));
        books.add(new Book("Visual C# How to Program","/images/small/vcshtp.jpg","/images/large/vcshtp.jpg"));
        booksListView.setItems(books);
        
        booksListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Book>() {
            @Override
            public void changed(ObservableValue<? extends Book> ov, Book oldValue,Book newValue) {
                coverImageView.setImage(new Image(newValue.getLargeImage()));
            }
        });

    }
}
alpine wigeon
#

This is where the error comes from

haughty otter
#

books.add(new Book("Android How to Program","C:\Users\x\Desktop\LAB2.3\src\images\large\chtp.jpg","C:\Users\x\Desktop\LAB2.3\src\images\large\\chtp.jpg"));

#

oh it works

#

i put the absolute path

#

thanks for helpingg

plush hawkBOT
# haughty otter thanks for helpingg

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

alpine wigeon
#

If you want to use the RELATIVE path, you can use a different method.

#
ImageView().setImage(new Image(getClass().getClassLoader().getResourceAsStream("path.img")));
#

Sorry I mean relative path

haughty otter
#

oh , valuable information , thank oyu

#

u