Android Question Problem with list

Discussion in 'Android Questions' started by mrossen, Mar 26, 2015.

  1. mrossen

    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.


    Code:
    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
     
  2. DonManfred

    DonManfred Expert Licensed User

    then you should look into the log. I´m sure there is an error.
     
  3. mrossen

    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)
     
  4. mrossen

    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
     
  5. DonManfred

    DonManfred Expert Licensed User

    Try to create a small example which shows this problem and upload this project here (IDE -> File -> Export as Zip)
     
  6. mrossen

    mrossen Active Member Licensed User

    Ok, thank you. I will do that later
     
  7. mrossen

    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.
     

    Attached Files:

  8. Erel

    Erel Administrator Staff Member Licensed User

    File.ReadList returns a list of strings. It reads the text file and returns each line as a single string item.

    If you are trying to save non-string values then you should use KeyValueStore class.
     
  9. mrossen

    mrossen Active Member Licensed User

    That Works perfect, :)

    Mogens
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice