Android Question expected receiver of type com.tutego.jrtf.Rtf, but got java.lang

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hello all,

Why am I getting this error while trying to use jRTF library ?

java.lang.IllegalArgumentException: expected receiver of type com.tutego.jrtf.Rtf, but got java.lang.Class<com.tutego.jrtf.Rtf>

Here is my code


B4X:
Sub jrtf2java
    Dim mjrtf As JavaObject
    mjrtf.InitializeStatic("com.tutego.jrtf.Rtf")
    Dim RtfText As JavaObject
    RtfText.InitializeStatic("com.tutego.jrtf.RtfText")   
    RtfText.RunMethodjo("bold",Array( "Hello RTF")).RunMethod("toString",Null)
    Dim writer As JavaObject
    writer.InitializeNewInstance("java.io.FileWriter",Array(File.Combine(File.DirRootExternal,"mout.doc"),False))
    mjrtf.RunMethodJO("out",Array(writer))
End Sub

The error is raised on the last line
mjrtf.RunMethodJO("out",Array(writer))

Please tell me in as much details as possible .

Thanks in advance
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Are you calling a static method?
I am not sure .
Here is a copy of library documentation :


 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
You need to create a new object with JavaObject.InitializeNewInstance.
I got this error java.lang.IllegalAccessException: access to constructor not allowed

when changing to
B4X:
mjrtf.InitializeNewInstance("com.tutego.jrtf.Rtf",Null)
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Sorry Erel .
It was me missing some method

Now this code should work with no problem

B4X:
Sub jrtf2java
    Dim mjrtf As JavaObject
    mjrtf.InitializeStatic("com.tutego.jrtf.Rtf")
    Dim RtfText As JavaObject
    RtfText.InitializeStatic("com.tutego.jrtf.RtfText")   
    RtfText.RunMethodjo("bold",Array( "Hello RTF")).RunMethod("toString",Null)
    Dim writer As JavaObject
    writer.InitializeNewInstance("java.io.FileWriter",Array(File.Combine(File.DirRootExternal,"mout.doc"),False))
    mjrtf.RunMethodJO("rtf",Null).RunMethodJO("out",Array As Object(writer))
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…