Android Question Try Catch - Error message

joilts

Member
Licensed User
Longtime User
Hi to everyone.

I'm having trouble with this code:

B4X:
Public Sub recognizePlateChar(dir As String, fileName As String, extension As String) As String
        NativeMe.InitializeContext
        File.Copy(dir,fileName&extension,global.dir, "1_"&fileName&extension)
        Dim retStr As String = ""
        Dim path As String = global.dir
        Dim name As String = "/1_"&fileName
        retStr = NativeMe.RunMethod("getPlate",  Array (path,name,extension,global.dir))
        Log(retStr)
        retStr = returnPlate(retStr)
        Log(retStr)
        Return(retStr)
End Sub

Running on a 4.1.1 (API 16) emulator I get this error message:

An error has occurred in sub: ocr_functions (java line:103) java.lang.reflect.InvocationTargetException

Tried to change for this code (inserting a try catch):
B4X:
Public Sub recognizePlateChar(dir As String, fileName As String, extension As String) As String
Try
        NativeMe.InitializeContext
        File.Copy(dir,fileName&extension,global.dir, "1_"&fileName&extension)
        Dim retStr As String = ""
        Dim path As String = global.dir
        Dim name As String = "/1_"&fileName
        retStr = NativeMe.RunMethod("getPlate",  Array (path,name,extension,global.dir))
        Log(retStr)
        retStr = returnPlate(retStr)
        Log(retStr)
        Return(retStr)
Catch
    Return("")
End Try
End Sub

The error message now is:

An error has occurred in sub: ocr_functions (java line:115) java.lang.ClassCastException: java.lang.ExceptionInInitializerError
cannot be cast to java.lang.Execption

Is there a way to fix the ClassCastException when using Try Catch structure?

Running the original code on a Nexus 5 (Android 6) and Galaxy S4 (Android 5), got no errors.

Thanks for your attention.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…