Android Question The specified child already has a parent. You must call removeView()...

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
I have this error:
B4X:
risposta : OK
dettaglioatleta$ResumableSub_RiempiItemresume (java line: 963)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    at android.view.ViewGroup.addViewInner(ViewGroup.java:3770)
    at android.view.ViewGroup.addView(ViewGroup.java:3623)
    at android.view.ViewGroup.addView(ViewGroup.java:3599)
    at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
    at com.mamavi.webfitness.dettaglioatleta$ResumableSub_RiempiItem.resume(dettaglioatleta.java:963)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1151)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5602)
    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:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

The code is:
B4X:
    Fotolo.Initialize("")
    Fotolo.RemoveView
    fotostruttura.Initialize(File.DirAssets,"webfitnesstrasp.png")
    Fotologo.Initialize(File.DirDefaultExternal,"logoasso.jpg")
    Fotolo.Bitmap=fotostruttura
    If Main.WFStrutturalogo<>"" Then
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download(Main.WFStrutturalogo)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Dim FotoBit As Bitmap = j.GetBitmap
        End If
        j.Release
        Fotolo.Bitmap = FotoBit
    End If
    wfNorizie.Panel.AddView(Fotolo, 20%x,wtop,60%x,30%x)
    Fotolo.Gravity=Gravity.FILL
Error is on addview statement.
Note that I use RemoveView....
Why happens it?
Thanks
Marco
 

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
I modified my code and call it both in create and in resume, but same error.
The error is on addview
I can't use designer cause wfNotizie is a scrollview.

B4X:
If Fotolo.IsInitialized Then
    Else
        Fotolo.Initialize("")
    End If
    fotostruttura.Initialize(File.DirAssets,"webfitnesstrasp.png")
    Fotologo.Initialize(File.DirDefaultExternal,"logoasso.jpg")
    Fotolo.Bitmap=fotostruttura
    If Main.WFStrutturalogo<>"" Then
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download(Main.WFStrutturalogo)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Dim FotoBit As Bitmap = j.GetBitmap
        End If
        j.Release
        Fotolo.Bitmap = FotoBit
    End If
    wfNorizie.Panel.AddView(Fotolo, 20%x,wtop,60%x,30%x)
    Fotolo.Gravity=Gravity.FILL
 
Last edited:
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
B4X:
wfNorizie.Panel.AddView(Fotolo, 20%x,wtop,60%x,30%x)

60%x, 30%x ????
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
It is only an example, then thereis this code:

B4X:
    Public hei, wid As String
    hei = Fotologo.Height
    wid = Fotologo.Width
'    Log ("hei: " & hei & " wid: " &wid)
    If (hei/wid<=0.5) Then
        Fotolo.Height=hei*Fotolo.Width/wid
    Else
        Fotolo.Width=wid*Fotolo.Height/hei
    End If
    Fotolo.Left=(100%x - Fotolo.Width) / 2

It works.
The problem is another......
Any idea?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
It is only an example, then thereis this code:

B4X:
    Public hei, wid As String
    hei = Fotologo.Height
    wid = Fotologo.Width
'    Log ("hei: " & hei & " wid: " &wid)
    If (hei/wid<=0.5) Then
        Fotolo.Height=hei*Fotolo.Width/wid
    Else
        Fotolo.Width=wid*Fotolo.Height/hei
    End If
    Fotolo.Left=(100%x - Fotolo.Width) / 2

It works.
The problem is another......
Any idea?


maybe upload a small project that demonstrates it. it would be simpler to check and find the problem.
 
Upvote 0
Top