I have a strange behavior in my code, but I cannot see the bug.
I create a TYPE and use it in an Array. Everything works fine. At the end I save all instances as Members of a MAP.
The file looks like this:
And the app crashes in the following start of the app, when loading the data. But not in the line where the map-datas are asigned to locSpur, but when I try to copy the locSpur into the array.
This is the error message:
When I try this, the app also survifes the first asignment, but crashes in the last line:
What do I do wrong?
I create a TYPE and use it in an Array. Everything works fine. At the end I save all instances as Members of a MAP.
B4X:
Sub Process_Globals
Type SpurenTyp(Name As String, Datei As String, Pan As Short,Volume As Short, Size As Int, Hertz As Int, Mono As Int, MaxPeak As Int )
...
Sub Globals
Dim SpurenDaten() As SpurenTyp
...
Sub BuildIt
For Each Datei As String In ResultListe
Dim locSpur As SpurenTyp=CreateSpurenTyp(BAS.SubStr(Datei,0,-4),Datei)
SpurenDaten(Nr)=locSpur
Next
End Sub
Public Sub CreateSpurenTyp (Name As String, Datei As String) As SpurenTyp
Dim t1 As SpurenTyp
t1.Initialize
t1.Name = Name
t1.Datei = Datei
t1.Pan =0
t1.Volume = 250
t1.Size = 0
t1.Hertz = 0
t1.Mono = 1
t1.MaxPeak=0
Return t1
End Sub
Sub SaveSongMap
For i=0 To 9
SongProp.put("Spur" & i , SpurenDaten(i))
Next
File.WriteMap(File.DirRootExternal, "test.dat",SongProp)
End Sub
Sub LoadSongMap
SongProp= File.ReadMap(File.DirRootExternal, "test.dat")
Dim locArray(10) As SpurenTyp
For i=0 To 9
Log("*****reading array=" & i & " " & SongProp.Get("Spur" & i))
Dim locSpur As SpurenTyp=SongProp.Get("Spur" & i)
locArray(i)=locSpur '<---------------- App crashes here
Next
End Sub
The file looks like this:
...
Info=no info
Spur0=[Datei\=ALTO 1.wav, Name\=ALTO 1, IsInitialized\=true\n, MaxPeak\=0, Mono\=1, Hertz\=48000\n, Pan\=0, Size\=10560414, Volume\=250\n]
HerstellerName=no name
SongName=IceCastle48
...
And the app crashes in the following start of the app, when loading the data. But not in the line where the map-datas are asigned to locSpur, but when I try to copy the locSpur into the array.
This is the error message:
*****reading array=0 [Datei=ALTO 1.wav, Name=ALTO 1, IsInitialized=true
, MaxPeak=0, Mono=1, Hertz=48000
, Pan=0, Size=10560414, Volume=250
]
zweite_loadsongmap (java line: 2010)
java.lang.ClassCastException: java.lang.String cannot be cast to midimaster.multitrack.zweite$_spurentyp
at midimaster.multitrack.zweite._loadsongmap(zweite.java:2010)
at midimaster.multitrack.zweite._readyesterday(zweite.java:2550)
at midimaster.multitrack.zweite._scanwavefiles(zweite.java:2812)
at midimaster.multitrack.zweite$ResumableSub_CheckeNeuenSong.resume(zweite.java:912)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1760)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5598)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
When I try this, the app also survifes the first asignment, but crashes in the last line:
B4X:
For i=0 To locAnzahlSpuren-1
Log("lese array " & i & " " & SongProp.Get("Spur" & i))
Dim locSpur As SpurenTyp=CreateSpurenTyp("","")
locArray(i)=locSpur
locSpur=SongProp.Get("Spur" & i)
locArray(i)=locSpur
....
Last edited: