Android Question List.Clear error!

Discussion in 'Android Questions' started by vecino, Jan 12, 2015.

  1. vecino

    vecino Well-Known Member Licensed User

    Hey, something strange.
    "UnsupportedOperationException" in list.clear
    I created a test project. The error is the same.

    Code:
    #Region  Project Attributes
       
    #ApplicationLabel: B4A Example
       
    #VersionCode: 1
       
    #VersionName:
       
    'SupportedOrientations possible values: unspecified, landscape or portrait.
       #SupportedOrientations: unspecified
       
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
       
    #FullScreen: False
       
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
       
    'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
    End Sub

    Sub Globals
       
    Private lv1 As ListView
       
    Private lv2 As ListView
       
    Dim ll As List
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
      
    Activity.LoadLayout("Fmain")
      ll.Initialize
    End Sub

    Sub Activity_Resume
    End Sub
    Sub Activity_Pause (UserClosed As Boolean)
    End Sub

    Sub Button1_Click
      
    Dim iX As Int
      lv1.Clear
      ll.Clear
      ll = 
    File.ListFiles("/usb1")
      
    For iX=0 To ll.Size-1
        lv1.AddSingleLine(ll.Get(iX))
      
    Next    
    End Sub

    Sub Button2_Click
      
    Dim iX As Int

      lv2.Clear
      ll.Clear

      ll = 
    File.ListFiles("/usb2")
      
    For iX=0 To ll.Size-1
        lv2.AddSingleLine(ll.Get(iX))
      
    Next
    End Sub
     

    Attached Files:

  2. KMatle

    KMatle Expert Licensed User

    You must initialize all views (lv1 + lv2) is not initialized (except you have defined it via designer). Maybe a typo?
     
  3. vecino

    vecino Well-Known Member Licensed User

    I have attached the test project :)
     
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    ListFiles returns a read-only list. You probably dont even need to clear it.
     
  5. vecino

    vecino Well-Known Member Licensed User

    I think I can delete any item from a list.
    Is not it?
     
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Not from a read-only list that is generated by ListFiles.
     
    vecino likes this.
  7. vecino

    vecino Well-Known Member Licensed User

    Oh!, I did not know :eek:, Thank You.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. vecino

    vecino Well-Known Member Licensed User

    Hello, thank you very much.
    I'm still a newbie in many things.
     
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