aspose file tools*
The moose likes Beginning Java and the fly likes Type Mismatch- Cannot convert from DrawImage to Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Type Mismatch- Cannot convert from DrawImage to Image" Watch "Type Mismatch- Cannot convert from DrawImage to Image" New topic
Author

Type Mismatch- Cannot convert from DrawImage to Image

John Forsmyth
Greenhorn

Joined: Oct 07, 2011
Posts: 2

I am attempting to call the "DrawImage" function from the "DrawImage" class file I made. It is supposed to return an image, but it spews an error every time it runs. Here's the DrawImage code:




Any advice on how to fix this problem?



Cheers
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

Welcome to the ranch!

I have added code tags to your post, making it much easier to read. Next time, just highlight your java, and click the 'code' button above, like you wanted to make something bold or italic.

It's kind of hard to answer your question. WHAT is the error you get? Believe it or not, that actually tells you a lot about what the problem is. May I suggest you check out our HowToAskQuestionsOnJavaRanch FAQ?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
John Forsmyth
Greenhorn

Joined: Oct 07, 2011
Posts: 2
Thanks! I'll take a look. The error is:






Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You're treating that method as if it were a constructor. You need to treat it as a proper method. So:
Note that this is actually bad design. First of all, you need to create an object to call the method. The method should be static instead, unless you want it to be overridden.
Second, you should never create methods with the same name as constructors / the class. It leads to confusion, and in your case to improper use of the method. I'd call the method loadImage instead, as the method doesn't draw anything - it loads an image from a file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
If it says unresolved compilation error, you should go back to Eclipse or whatever and correct every red mark before you try to run anything.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Type Mismatch- Cannot convert from DrawImage to Image
 
Similar Threads
Rules Roundup game
Please explain these answers
Need help on two compile errors
this roundup question trips me up every time
Saving a Jpanel as a JPEG