Cant load images in Eclipse

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
LinuxLewis

Cant load images in Eclipse

Post by LinuxLewis »

Im trying to write a game in Java using Eclipse (with acm plugins if I've got the terminology right), but I cant seem to load images, it cant even find them.
Not sure if its Eclipse or my complete lack of programing ability, but as I've been at it less than a fortnight, probably the latter :D
Im trying to call it with

Code: Select all

new GImage(bgimage.jpg, 0, 0);
and a few variations there of, but whatever I seem to type, it seems happy with everything but the file name which gets underlined and tells me it couldnt be resolved. I tried adding it as a private instance variable, I've tried putting the image in the workspace folder, the project folder, the src directory of the project folder and I've created a folder called images, put it in there and moved the folder around, I've also tried other images (jpgs & gifs) to make sure the image file itself isnt the problem, but it still doesnt want to find it.
I figured it must be a problem with my code, however when I use the eclipse tool bar to search for files it doesnt return any image files there either, which made me wonder if its an eclipse issue after all.
Any advice would be very much appreciated, I've been stuck on it for hours..I've got the game working, I really thought chucking a background image in would be the easy bit!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Cant load images in Eclipse

Post by xenopeek »

Shouldn't that be:
new GImage("bgimage.jpg", 0, 0);

And perhaps just give the full path here, e.g.:
new GImage("/home/LinuxLewis/some/where/bgimage.jpg", 0, 0);

Or perhaps try another language (pst, Python :D).
Image
yanaesco

Re: Cant load images in Eclipse

Post by yanaesco »

xenopeek wrote:Shouldn't that be:
new GImage("bgimage.jpg", 0, 0);

And perhaps just give the full path here, e.g.:
new GImage("/home/LinuxLewis/some/where/bgimage.jpg", 0, 0);

Or perhaps try another language (pst, Python :D).

thanks for your solution
LinuxLewis

Re: Cant load images in Eclipse

Post by LinuxLewis »

xenopeek wrote:Shouldn't that be:
new GImage("bgimage.jpg", 0, 0);

And perhaps just give the full path here, e.g.:
new GImage("/home/LinuxLewis/some/where/bgimage.jpg", 0, 0);
Thank you very much Vincent, the quote's did the job, I hoped it'd be something simple like that!
xenopeek wrote: Or perhaps try another language (pst, Python :D).
I'm its on the agenda...I read alot of threads in different forums along the lines of "what language should I learn" and it seemed everyone had a different oppinion so I just went with the first one I found a decent free online course for (http://www.academicearth.org/courses/pr ... ethodology if anyones interested). I've since looked around the site and they do have courses for other languages, so my current plan is to finish this series, then take a course on another language and as well as doing those assignments, translate (or entirely rewrite..not quite sure how that works yet!) my current assignments untill I've got a decent grasp of java, python and c++/maybe c. Then come back here and show Clem how its done.. Haha perhaps not, but if I can squash some bugs and maybe (one day) get something in the repositorys that'd be pretty cool (and look pretty good on my CV).
Locked

Return to “Software & Applications”