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

Reids

Member
Licensed User
Longtime 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
B4X:
Dim cu As ContactsUtils
cu.Initialize
Log(cu.GetPhones(id))

It show (ArrayList) [[PhoneType=mobile, Number=00000000, IsInitialized=true]]

I tried to use
B4X:
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
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Reids

Member
Licensed User
Longtime User
Contact Utils Part
B4X:
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"), id, Null)
		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

B4X:
Dim a As Map
a=cu.GetPhones(id).Get(0)
Log(a.Get(0))

Returned
B4X:
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)
B4X:
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
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
is it from the contactutils class?

there are the types defined....
B4X:
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

B4X:
Dim a As cuPhone
a=cu.GetPhones(id).Get(0)
should do the trick
 
Upvote 0

Reids

Member
Licensed User
Longtime User
But it return
B4X:
(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
B4X:
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:
Upvote 0
Top