Android Question Reading Value of List Type [PhoneType=mobile, Number=00000000, IsInitialized=true

Discussion in 'Android Questions' started by Reids, Jul 15, 2016.

  1. Reids

    Reids Member Licensed User

    I tried to parsing Contact Utils GetPhones() value (ArrayList) [[PhoneType=mobile, Number=00000000, IsInitialized=true]]
    I want to display Number value which print 0000000
    Part of my code is
    Code:
    Dim cu As ContactsUtils
    cu.Initialize
    Log(cu.GetPhones(id))
    It show (ArrayList) [[PhoneType=mobile, Number=00000000, IsInitialized=true]]

    I tried to use
    Code:
    Dim cu As ContactsUtils
    cu.Initialize
    Log(cu.GetPhones(id).get(0))
    It only print [PhoneType=mobile, Number=00000000, IsInitialized=true]
    I don't know how to parse number value


    Thanks
     
  2. DonManfred

    DonManfred Expert Licensed User

    check what .get returns... Maybe a map?
     
  3. Reids

    Reids Member Licensed User

    Contact Utils Part
    Code:
    Public Sub GetPhones(id As Long) As List
        
    Dim res As List
        res.Initialize
        
    For Each obj() As Object In GetData("vnd.android.cursor.item/phone_v2"Array As String("data1""data2"), idNull)
            
    Dim p As cuPhone
            p.Initialize
            p.Number = obj(
    0)
            p.PhoneType = phoneTypes.Get(obj(
    1))
            res.Add(p)
        
    Next
        
    Return res
    End Sub

    Activity Part
    I tried to parse as map too

    Code:
    Dim a As Map
    a=cu.GetPhones(
    id).Get(0)
    Log(a.Get(0))
    Returned
    Code:
    Error occurred on line: 164 (Main)
    java.lang.ClassCastException: org.myapps.apps.contactsutils$_cuphone 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.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    515)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:703)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:337)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:247)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    515)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    134)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    153)
        at anywheresoftware.b4j.object.JavaObject$
    1.invoke(JavaObject.java:237)
        at $Proxy0.ResultArrived(Native Method)
        at anywheresoftware.b4a.BA$
    4.run(BA.java:513)
        at anywheresoftware.b4a.BA.setActivityPaused(BA.java:
    398)
        at org.neoblackant.pulsa.main$ResumeMessage.run(main.java:
    296)
        at android.os.Handler.handleCallback(Handler.java:
    733)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    136)
        at android.app.ActivityThread.main(ActivityThread.java:
    5146)
        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:
    732)
    I tried this without .get(0)
    Code:
    Error occurred on line: 163 (Main)
    java.lang.ClassCastException: java.util.ArrayList 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.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    515)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:703)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:337)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:247)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    515)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    134)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    153)
        at anywheresoftware.b4j.object.JavaObject$
    1.invoke(JavaObject.java:237)
        at $Proxy0.ResultArrived(Native Method)
        at anywheresoftware.b4a.BA$
    4.run(BA.java:513)
        at anywheresoftware.b4a.BA.setActivityPaused(BA.java:
    398)
        at org.neoblackant.pulsa.main$ResumeMessage.run(main.java:
    296)
        at android.os.Handler.handleCallback(Handler.java:
    733)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    136)
        at android.app.ActivityThread.main(ActivityThread.java:
    5146)
    Maybe ArrayList
     
  4. DonManfred

    DonManfred Expert Licensed User

    is it from the contactutils class?

    there are the types defined....
    Code:
    Type cuContact (Id As Long, DisplayName As String)
    Type cuEmail (Email As String, EmailType As String)
    Type cuPhone (Number As String, PhoneType As String)
    Type cuEvent (DateString As String, EventType As String)
    So

    Code:
    Dim a As cuPhone
    a=cu.GetPhones(
    id).Get(0)
    should do the trick
     
    Reids likes this.
  5. Reids

    Reids Member Licensed User

    But it return
    Code:
    (ArrayList) [[PhoneType=mobile, Number=00000000, IsInitialized=true]]
    All I wanted just a "Number" value inside that array list
    just print the 000000 value, the main problem is I don't know how to convert those ArrayList to a long type or string type





    EDIT

    Ah solved by
    Code:
    Dim allContacts As List = cu.GetPhones(id)
        
    For Each c As cuPhone In allContacts
          
    Log(c.Number)
       
    Next
    Thanks for your concern, I just take deep look on your post about cuPhone type
    Thank You!
     
    Last edited: Jul 15, 2016
    DonManfred likes this.
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