Error occured at line #57:
Waiting for debugger to connect...
Program started.
Error occurred on line: 57 (Main)
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at anywheresoftware.b4j.object.JavaObject.InitializeArray(JavaObject.java:109)
at b4j.example.main._testwrite(main.java:91)
at b4j.example.main._appstart(main.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at b4j.example.main.main(main.java:29)
Program terminated (StartMessageLoop was not called).
Waiting for debugger to connect...
Program started.
Error occurred on line: 57 (Main)
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at anywheresoftware.b4j.object.JavaObject.InitializeArray(JavaObject.java:109)
at b4j.example.main._testwrite(main.java:91)
at b4j.example.main._appstart(main.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at b4j.example.main.main(main.java:29)
Program terminated (StartMessageLoop was not called).
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#AdditionalJar: jdbf-1.2.jar
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
TestWrite
End Sub
Sub TestRead
' Set charset to GBK
Dim CSet As JavaObject
CSet.InitializeStatic("java.nio.charset.Charset")
Dim cs As Object = CSet.RunMethod("forName", Array As String("GBK"))
' Initialize DBF Reader
Dim dbfReader As JavaObject
dbfReader.InitializeNewInstance("com.hexiong.jdbf.DBFReader", Array As Object ("testwrite.dbf"))
' Get field name
Dim FieldsName As String
Dim FieldsCount As Object = dbfReader.RunMethod("getFieldCount", Null)
For i = 0 To FieldsCount - 1
Dim Fld As JavaObject = dbfReader.RunMethod("getField", Array As Object(i))
Dim Nam As String = Fld.RunMethod("getName", Null)
FieldsName = FieldsName & $"${Nam} | "$
Next
Log(FieldsName)
' Read fields
i = 0
Do While dbfReader.RunMethod("hasNextRecord", Null)
Dim res() As Object = dbfReader.RunMethod("nextRecord", Array As Object(cs))
Dim row As String
For Each Field In res
row = row & $"${Field} | "$
Next
Log(row & CRLF)
i = i + 1
Loop
Log("Total Count: " & i)
' Close the dbf file
dbfReader.RunMethod("close", Null)
End Sub
Sub TestWrite
' Initialize JDB Fields
Dim JDBField As JavaObject
Dim col1 As JavaObject = JDBField.InitializeArray("com.hexiong.jdbf.JDBField", Array As Object("ID", "C".As(Char), 8, 0))
Dim col2 As JavaObject = JDBField.InitializeArray("com.hexiong.jdbf.JDBField", Array As Object("Name", "C".As(Char), 254, 0))
Dim col3 As JavaObject = JDBField.InitializeArray("com.hexiong.jdbf.JDBField", Array As Object("TestN", "N".As(Char), 20, 0))
Dim col4 As JavaObject = JDBField.InitializeArray("com.hexiong.jdbf.JDBField", Array As Object("TestF", "F".As(Char), 20, 6))
Dim col5 As JavaObject = JDBField.InitializeArray("com.hexiong.jdbf.JDBField", Array As Object("TestD", "D".As(Char), 8, 0))
Dim JDBFields As JavaObject
Dim fields() As Object = JDBFields.InitializeArray("com.hexiong.jdbf.JDBField", Array(col1, col2, col3, col4, col5))
' Initialize DBF Writer
Dim dbfWriter As JavaObject
dbfWriter.InitializeNewInstance("com.hexiong.jdbf.DBFWriter", Array As Object ("testwrite.dbf", fields))
Dim row1 As Object = Array("1", "hexiong ", 500, 500.123, DateTime.Date(DateTime.Now))
Dim row2 As Object = Array("2", " hefang ", 600, 600.234, DateTime.Date(DateTime.Now))
Dim row3 As Object = Array("3", "hexi01234567890123456789012345678901234567890123456789" & _
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" & _
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", 600, 600.234, DateTime.Date(DateTime.Now))
Dim row4 As Object = Array("4", "heqiang", 700, 700.456, DateTime.Date(DateTime.Now))
Dim records() As Object
records = Array As Object(row1, row2, row3, row4)
For i = 0 To records.Length - 1
dbfWriter.RunMethod("addRecord", Array As Object(records(i)))
Next
' Close the dbf file
dbfWriter.RunMethod("close", Null)
Log("testwrite.dbf write finished.......")
TestRead
End Sub