aspose file tools*
The moose likes Beginning Java and the fly likes Cannot call method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot call method" Watch "Cannot call method" New topic
Author

Cannot call method

David Schmidt
Greenhorn

Joined: Jan 02, 2011
Posts: 15

I want to call "setI" from class1. Can somone help me and show me what is wrong?








Java is treating MyPanel exactly like a JPanel, and won't let me create any new methods for it
However I need to be able to call custom (and non-static) methods from the class. Is this possible?
If not, any alternatives?


My MCRS certification:
http://i54.tinypic.com/1z6s9rr.png

Microsoft Certified Reboot specialist
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I assume that when you say "Does not work", you mean that there is a compiler error. MyPanel.setI(int i) expects an integer as an input parameter. Do you know how to do this when calling the method?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7




You need to pass an int variable to the setI(...) method.
David Schmidt
Greenhorn

Joined: Jan 02, 2011
Posts: 15

Once I changed that, it worked... which is really confusing. I tried to replicate a problem from a larger program without posting the code.

The error I get is
The method setDrawValues(String, int, int, int, int) is undefined for the type JPanel

I think it is a very stupid mistake, but I can't find it. I'll post the necessary code here:
David Schmidt
Greenhorn

Joined: Jan 02, 2011
Posts: 15

Moreover, when I type in graph. [CTRL + SPACE], "setDrawValues" is not even visible in the intellisense menu.
This is really confusing
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You've declared graph as a JPanel. This means you can only call methods that are available in JPanel.

These two problems are not directly related to GUI programming so I'm moving this thread to Beginning Java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Schmidt
Greenhorn

Joined: Jan 02, 2011
Posts: 15

thank you.

Anyway, after some trial and error I managed to solve this by like this:


Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Whereas you created a MyGraphPanel, the variable graph is defined as a JPanel, which is fine because MyGraphPanel ISA JPanel. JPanel, however, does not have a setDrawValues() with the parameters that you specify.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot call method