From: Updike, C. <Cla...@jh...> - 2004-10-04 13:01:02
|
Should line 25 perhaps be: flow.embedImage(con.getImage(), size) #Line 25 <-- note the parans on getImage() -Clark -----Original Message----- From: On Behalf Of Katherine Wong Sent: Monday, September 27, 2004 11:09 AM To: jyt...@li... Subject: [Jython-users] Accessing Java methods from Jython class Hello Jython-users, I'm new to Jython and is encountering the following problem...Hoping to get some insight. In my test.py I have the following method: def addContent(self): con = Content() flow = JCFlow(self.document) flow.print(con.getParagraph()) #Line 23 flow.newLine() flow.embedImage(con.getImage, size) #Line 25 In my Content.java, I have setup the following methods: public String getParagraph() { String para = "Some paragraph...."; return para; } public Image getImage() { String imageFile = "logo.gif"; URL imageUrl = this.getClass().getResource(imageFile); if (imageUrl == null) { throw new IllegalStateException("File not found " + imageFile); } Image logo = new ImageIcon(imageUrl).getImage(); return logo; } When I ran the test.py, I get the following error: ---------------- Traceback (innermost last): File "GenerateReport.py", line 54, in ? File "GenerateReport.py", line 15, in __init__ File "GenerateReport.py", line 23, in addContent TypeError: print(): 1st arg can't be coerced to com.klg.jclass.sreport.TextMacro, String or com.klg.jclass.sreport.JCPageTable ---------------- From the error I knew this has something to do with overloading method b/c flow.print() has the following variant: flow.print(String) flow.print(com.foo.TextMacro) flow.proint(com.foo.Table) So I changed Line 23 to: flow.print(String(con.getParagraph())) Now, I get the following error: ---------------- Traceback (innermost last): File "GenerateReport.py", line 54, in ? File "GenerateReport.py", line 15, in __init__ File "GenerateReport.py", line 23, in addContent TypeError: java.lang.String(): 1st arg can't be coerced to char[], java.lang.StringBuffer, byte[] or String ---------------- I'm not sure how to resolve this. I have the same problem with Line 25: ---------------- Traceback (innermost last): File "GenerateReport.py", line 54, in ? File "GenerateReport.py", line 15, in __init__ File "GenerateReport.py", line 25, in addContent TypeError: embedImage(): 1st arg can't be coerced to java.awt.Image ---------------- If I change Line 25 to: ---------------- Traceback (innermost last): flow.embedImage(java.awt.Image(con.getImage), size) File "GenerateReport.py", line 54, in ? File "GenerateReport.py", line 15, in __init__ File "GenerateReport.py", line 25, in addContent TypeError: can't instantiate abstract class (java.awt.Image) ---------------- Please Help! Thanks, Kat |