#imageview cannot find the image file
1 messages · Page 1 of 1 (latest)
<@&987246487241105418> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
if someone answers I will send the code
that's not how things work, you first give detail, then someone answers
yeah.. that's what happened before, but none answered anyways
anyways
so basically
I put all my data in a json file
like this:
if (file.exists()) {
String imagePath = getClass().getResource(profileData.getAvatar()).toExternalForm();
Image image = new Image(imagePath);
System.out.println("Image loaded from: " + imagePath);
if (image != null) {
picc.setImage(image);
} else {
System.out.println("Image could not be loaded.");
}
}
image can't be null
ik but
this is the json
{
"nickname": "de",
"avatar": "C:\\Users\\Andrew\\Pictures\\Roblox\\RobloxScreenShot20230701_234606681.png",
"partiteGiocate": 0,
"partiteVinte": 0,
"partitePerse": 0,
"livello": 0,
"password": "dee"
},
Detected code, here are some useful tools:
so
if you know, why do you test if it is null ?
the issue might be this "\\"
because it might be sometimes
just for debugging
why
because new keyword will never return null
ah
alr, imma change that soon
but
the issue lays afterward
lemme show u
I mean before
because, once the image is set
it will be like this:
if (selectedFile != null) {
Image selectedImage = new Image(selectedFile.toURI().toString());
// Get the name of the selected file
String filePath = selectedFile.getPath().toString();
filePath = filePath.replace("/", "\\");
System.out.println("Selected file name: " + filePath);
Avatar.setText(filePath);
profiloplayer.getInstance().getProfilo().setAvatar(filePath);
profiloplayer.getInstance().getProfileManager().saveToJson();
} else {
Avatar.setText("No Image Selected");
}
Detected code, here are some useful tools:
then this comes afterwards, because its in the iniziale method
so essentially the issue could be this:
String imagePath = getClass().getResource(profileData.getAvatar()).toExternalForm();
because every time thats where the program stops working
meaning that the file path is wrong
also
getClass().getResource(profileData.getAvatar()).toExternalForm()
This won't work if you use a jar
which jar?
filePath = filePath.replace("/", "\");
This is system dependent, please don't do that
your app jar, if you build your app in a jar, it will break
couldn't it be that the program searches for the path with \ but finds the path with //?
I don't know what you are trying to do here but don't do that please
show the path you are using and the place where your image is
I am talking about how you build it
I get the absolute path
wym
in order to run your program, you have to build it, to compile it
example ?
I put the absolute path in the json file like here and then I use that same path for the img
ah well
it does build
yes
there are two ways to build your program, either into a folder, or into a jar, if it's into a jar, your approach breaks
oh then its fine, its within a folder
anyways
lemme show u the program a bit deeply
so ?
about the file?
yeah thats the path here
it can't work
you can only use things that are in resources folder with Class.getResource
it wouldn't make sense otherwise
not with getResource, it wouldn't make any sense, why are you trying to do that ?
because the user might want to get his image somewhere
but the user won't fill this json right ?
no
its kinda like when u send an image from discord
I made a little window where you can select yoru files
right
aka the file chooser class
then yes, using getResource here doesn't make sense
getResource is if you want to get programresources, things that you build and ship with your program
so in order to set the image into an imageview while having the absolutepath I have to use Io?
here you want to use io
so I just create a file with the path and give it to the Image object?
what is the class of this Image ? java.awt.Image ?
javafx.scene.image.Image;
file object*
just pass in the path the user is giving you
@tired pendant also how did you coded the gui to ask the user an image to use ?
because its like the preffered avatar
I asked "how", not "why"
because the gui is about your profile
so you can insert
all the data
while the rest is entered by the game
please answer my question
how did you coded the gui to ask the user an image to use ?
ahh I misred
just created the profile gui and used the file chooser thing
ah right thank you
np