Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Type Mismatch- Cannot convert from DrawImage to Image

 
John Forsmyth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
John Forsmyth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I'll take a look. The error is:






 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic