Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why do some of my images load in jar files made in BlueJ, but some don\'t? I use

ID: 3854696 • Letter: W

Question

Why do some of my images load in jar files made in BlueJ, but some don't?

I used some of the information around this site to find out to use URLs to get images into a jar file; which I want to be able to be used alone. But when I make the jar file with BlueJ, only some images show up.

Its a blackjack game, and only the table canvas shows up, while no cards ever do. Here's the code:

THIS WORKS (the table):

but this does not (the cards):

my cards are in a folder in the directory I try to import into BlueJ, whereas the table is in the directory root. There are 53 cards in there (incl dealer hidden card) and I'd rather not put all of then in the root. I tried to implement them similarly. How can I do this?

Explanation / Answer

You can try to change the path to use / instead of \

so change the code to

URL cardview = getClass().getResource("/card deck/DEALER_FIRST_CARD.png");

Also, make sure the filename is being set correctly ! (to match the names of files on your system. In linux they will be case-sensitive.)

The forward / will work on all systems. Check and let me know if it works or not. Post a comment. If it worked, please rate the answer. If still you are facing problem, let me know.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote