#Region
#AdditionalJar: jaudiotagger-2.2.5
#EndRegion
Sub xx
Dim jo As JavaObject
jo.InitializeStatic("org.jaudiotagger.audio.AudioFileIO")
Dim dir As String ="C:\Work"
Dim Name As String=Music.mp3"
Dim jo2 As JavaObject=jo.RunMethod("checkFileExists, Array(File.Combine(dir,Name)))
End Sub
I get a java.lang.RuntimeExeption: Method: checkFileExists not matched
So i think the second Parameter is wrong!?
Whats my mistake here?
i found the solution:
it works with a JavaObject 'File'
B4X:
Dim javafile As JavaObject
javafile.InitilaizeNewInstanve("Java.io.File", Array (File.Combine(dir,name)))
' forgotten in last post:
Dim jo2 As JavaObject=jo.RunMethod(getDefaultAudioFileIO", Null)
jo2.RunMethod("checkFileExists",Array As Object(javafile)))
'the Tags for instance:
log(jo2.RunMethod("read", Array As Object(javafile)))
Problem:
the checkFileExists Method crashes when the File didnt exist.....!!!??? lol
I tryed the checkFileExists Method from the jAudioTagger lib just to see if i do the Java-Object-Calls in the right way.
Just for learning this.
Using the jAudiotagger Lib is just a example for me, it could be any other Lib with no Wrapper.
Because i get an error with the call of the checkFileExists Method (if the file not exists), i think i am doing something wrong in my code.
Any error to see?
' https://www.b4x.com/android/forum/threads/get-the-fileicon-from-a-file.63866/#content
'"File" should be a java File object, not full path string.
Dim JavaFile As JavaObject
JavaFile.InitializeNewInstance("java.io.File", Array(File.Combine(dir, name)))
'edit
Looking at the API docs - checkFileExists doesn't return a value to say the file exists.(It's declared void) It simply raises an exception if the file doesn't exist.
So you probably need to put the 'checkFileExists' code in a try - catch block
If it doesn't get caught - the fie exists.
B4X:
...
Dim ja As JavaObject
ja.InitializeNewInstance("org.jaudiotagger.audio.AudioFileIO",Null)
Dim dir As String ="c:/temp/"
Dim Name As String = "test.mp3"
Dim jo As JavaObject
Try
ja.RunMethod("checkFileExists", Array(jo.InitializeNewInstance("java.io.File",Array(dir & Name))))
Catch
If LastException.Message.Contains("FileNotFoundException") Then
Log("the file is missing")
Else
Log("something else broke")
End If
End Try
...
thanks a lot, billzhan and Daestrum for your contribution.
ok, now this behavior make sense for me.
I thougt that in general a "check for something" method gives back a value for this.
So i learned: not to be sure of a matter of course.......