Re: Image Drawing Problem
What happens if you do this:
Code java:
System.out.println(new File("ghost.jpeg").exists());
Re: Image Drawing Problem
Im getting the false output so its not located... So its the path name then?
Re: Image Drawing Problem
Quote:
Originally Posted by
Matta
Im getting the false output so its not located... So its the path name then?
Sounds like it. You might want to check where the class files (as opposed to the .java files) are located. Or you might want to use the full path.
Or you could try printing out the full path of the file (the one that doesn't exist) to see where Java thinks it is.
Re: Image Drawing Problem
I have actually tried to use the full path of the image, where it is located im still getting the false error also this was known as I started of using this.getClass(),getResources("C:/Images/Ghost.jpg"); Edit: Oh and also if i added it to the where the class is i would use the workspace directory then test1/Images/Ghost.jpg")
Then I got the nullpointexception which kinda states the same that he image is not found.
Edit: I have read up a bit the image i have is created in paint which shouldnt make any difference, i just put it inside where my code is now in the src folder. That is suppose to work atleast what i have read but it doesnt! This is really frustrating...
Re: Image Drawing Problem
Your code works for me, if I create a ghost.jpeg image and place it in the same folder as my .java and .class files.
Are you using packages? Are you sure you have the filename right (jpg vs jpeg, capitalization)?
Re: Image Drawing Problem
Yeah im pretty sure i have the right jpg stuff atleast i looked at my image properties and it said jpg so thats what im using. But thats the basics.
Im not using any packages no. I have a folder called workspace where all my src files are located this is the right one, right? Ill get home and try it on my main computer which maybe is able to take it.
But i have the eclipse or the workspace in different directories, or my directory for workspace is located in my user and the eclipse is folder is located on the mainboard of the computer. Aaah .. pain.. so you get it to work then its only my computer who screws everything up! i knew it...
Re: Image Drawing Problem
It sounds like eclipse is putting the .class files in a different folder from your .java files, which is pretty normal. Oftentimes, people will store the images in a separate folder, then do something like "../images/image.jpg" to go up a directory, then into the images folder, then find the image. You could also copy your image file to the bin folder (or wherever your .class files are going).
Don't just look at the image file properties- a jpg file can have an extension of .jpg or .jpeg, or .JPG for that matter. Look at the actual file name.
I recommend ditching eclipse for a second- move the .java and the .jpg file to the desktop, then compile and run the file from the command line.
Re: Image Drawing Problem
Incidentally, it's not a good idea to call g.dispose() at the end of the paint method. Graphics resources are automatically released after the paint method, and disposing of them yourself can bite you if you decide to subclass and override that method to extend it. Only dispose of graphics objects that you have created or extracted from a component yourself.