Android Question Problem with list

mrossen

Active Member
Licensed User
Hi,

I have a dataset I get from a mysql database.

If I get the data right I store the record in a txt file with file.writelist

If I dont have data connection I read the dataset with file.readlist, but something seems not to be done right.

I hope someone can see what I have made right

I get no error but the app craches.


B4X:
Sub JobDone(Job As HttpJob)
  
    Dim oldData, newData As String
    Dim partNoAll As String
      
    brand_cars.Initialize
      
    Dim lType As List
  
    lType.Initialize
  
  
  
    ListViewCars.TwoLinesLayout.Label.Textsize = 16
    ListViewCars.TwoLinesLayout.SecondLabel.Textsize = 14
  
      
    ProgressDialogHide
    If Job.Success Then
    Dim res As String
        res = Job.GetString
  
        Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
            Case brand
          
                brand_list = parser.NextArray 'returns a list with maps
                 
                For i = 0 To brand_list.Size - 1
                    mAll = brand_list.Get(i)
                    partNoAll = mAll.Get("partno")

                    newData = mAll.Get("brand") & " - " & mAll.Get("model") & " - " & mAll.Get("engine") & " - " & mAll.Get("yearfrom") & " - " & mAll.Get("fuel") & " - " & mAll.Get("variant") & " - " & partNoAll.CharAt(5)
                                      
                    If newData <> oldData Then
                        brand_cars.Add(brand_list.Get(i))
                    End If
                      
                    oldData = mAll.Get("brand") & " - " & mAll.Get("model") & " - " & mAll.Get("engine") & " - " & mAll.Get("yearfrom") & " - " & mAll.Get("fuel") & " - " & mAll.Get("variant")  & " - " & partNoAll.CharAt(5)
                  
                Next
          
                File.WriteList(File.DirRootExternal, "ListBrand.txt", brand_cars)
              
                getCars
              
        End Select
    Else
        ToastMessageShow("No internet connection", True)
      

        brand_cars = File.ReadList(File.DirRootExternal, "ListBrand.txt")
        getCars
      
      
    End If
    Job.Release

                  
                  
End Sub
 

mrossen

Active Member
Licensed User
Yes there are, but first later in the code, when I try to access the. For me it looks like I load an empty list

Error:


Error occurred on line: 335 (main)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:65)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:332)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
 

mrossen

Active Member
Licensed User
But if I make a breakpoint at the codeline : getCars after I have read the list, I get no error.

But if I then try to hover "brand_cars" to see what is in the list, the app terminates

Mogens
 

mrossen

Active Member
Licensed User
Now I have made a test app

Start the app with internet connection and it will list car brands in the log.

Disable internet connection and start the app Again.

It will now crach.
 

Attachments

Top