java.lang.StringBuffer

aedwall

Active Member
Licensed User
Longtime User
I have a library that contains a function and one of the parameters I pass to this function is of the type "java.lang.StringBuffer". What is the equivalent to this in b4a? Thank you.

Sub Get_1_Planet(JD As Double, p_num As Int) As Double
Dim xx(7) As Double
Dim serr As String 'serr must be a java.lang.StringBuffer
Dim iflag As Int
Dim ret_flag As Int

serr = ""
For i = 0 To 255
serr = serr & " "
Next

iflag = 258

ret_flag = swe1.swe_calc_ut(JD, p_num, iflag, xx, serr)

Return xx(0)
End Sub

The function documentation says this:

public int swe_calc_ut(double tjd_ut,
int ipl,
int iflag,
double[] xx,
java.lang.StringBuffer serr)
 

Attachments

  • ScreenShot_01-27-12 23.gif
    ScreenShot_01-27-12 23.gif
    9.5 KB · Views: 187

stevel05

Expert
Licensed User
Longtime User
StringBuffer is not represented in B4A and is largely replaced in java by StringBuilder see here

You can however create an stringbuffer object using AGrahams reflection library, your code would need to be similar to this:

B4X:
Dim r As Reflector

   ret_flag = swe1.swe_calc_ut(JD, p_num, iflag, xx, r.CreateObject2("java.lang.StringBuffer",Array As Object(serr),Array As String("java.lang.String")))

If you have created the library, it would probably be better to change the library to accept a string or string builder and convert it within the library.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Thank you for your response. After reading up on it, I decided to change all references to "StringBuffer" to "StringBuilder" in the original .java files that make up the library. This apparently works as I am able to now compile and launch the application. Thanks for your help and I have downloaded the Reflection library and will investigate it.
 
Upvote 0
Top