Android Question [SOLVED] Amir_Glide throws Exception "You must not call setTag() ...". What is needed to do?

fredo

Well-Known Member
Licensed User
Amir_RecycleView is of great benefit in terms of a modern UI. To load images, the Amir_Glide lib is used in the rich sample projects.

During the attempt to use the Amir_Glide lib in a new project the following error occurs:
java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting


#-Sub arv_onBindViewHolder, Position=0
~e:main_loadimage (java line: 614)
java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
at com.bumptech.glide.request.target.ViewTarget.getRequest(ViewTarget.java:265)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:603)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:682)
at ir.aghajari.retrofitglide.Amir_RequestBuilder.Into(Amir_RequestBuilder.java:161)
at b4a.example.main._loadimage(main.java:614)
at b4a.example.main._arv_onbindviewholder(main.java:415)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.aghajari.rv.Amir_RVAdapter$Amir_RVAdapterWrapper.onBindViewHolder(Amir_RVAdapter.java:152)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:19726)
at android.view.ViewGroup.layout(ViewGroup.java:6104)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:43)
at android.view.View.layout(View.java:19726)
at android.view.ViewGroup.layout(ViewGroup.java:6104)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19726)
at android.view.ViewGroup.layout(ViewGroup.java:6104)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:498)
at android.view.View.layout(View.java:19726)
at android.view.ViewGroup.layout(ViewGroup.java:6104)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19726)
at android.view.ViewGroup.layout(ViewGroup.java:6104)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2590)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2285)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1433)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6930)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:982)
at android.view.Choreographer.doCallbacks(Choreographer.java:784)
at android.view.Choreographer.doFrame(Choreographer.java:713)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:968)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:180)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:837)

B4X:
Sub arv_onBindViewHolder (Parent As Panel, Position As Int)
    Log("#-Sub arv_onBindViewHolder, Position=" & Position)
    'Log("#-  x111, Parent.Tag=" & Parent.Tag)
    
    
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    ' This fills the item content from the Dataset
    ' corresponding to the position
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    Dim panBack As Panel = Parent.GetView(0)
    Dim Label1 As Label = panBack.GetView(0)
    Dim Label2 As Label = panBack.GetView(1)
    Dim ImageView1 As ImageView = panBack.GetView(2)

    Dim arvItemX As arvItem = DataSet.Get(Position)   
    Label1.Text = arvItemX.Title
    Label2.Text = arvItemX.Description

    Parent.Tag = arvItemX.ImagePath
    LoadImage(ImageView1, arvItemX.ImagePath)

    panBack.Height = Label1.Height +Label2.Height +(Label1.Top *2)     
    Parent.Height = panBack.Height +8dip
    
End Sub

Public Sub LoadImage (Img As ImageView, ImageName As String)
    Dim Glide As Amir_Glide
    Glide.Initializer.Default

    ' ###### ErrMsg: ~e:main_loadimage (java line: 614), java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting

    Glide.LoadWith.File(File.DirAssets, ImageName).Apply(Glide.RO.CenterCrop).Transition(Glide.TO.WithCrossFade).Into(Img)



End Sub

Has the lib possibly been used incorrectly?

A small testproject is attached below.
 

Attachments

fredo

Well-Known Member
Licensed User
I think ...
Thank you. That was the needed hint to overcome the error.​

... only a blank ...
This led to the realization that images of DirAsset can be accessed as follows:
B4X:
Glide.LoadWith.URI("file:///android_asset/" & ImageName)

B4X:
Sub arv_onBindViewHolder (Parent As Panel, Position As Int)
'    Log("#-Sub arv_onBindViewHolder, Position=" & Position)
    
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    ' This fills the item content from the Dataset
    ' corresponding to the position
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    Dim panBack As Panel = Parent.GetView(0)
    Dim Label1 As Label = panBack.GetView(0)
    Dim Label2 As Label = panBack.GetView(1)
    Dim ImageView1 As ImageView = panBack.GetView(2)
    
    Dim arvItemX As arvItem = DataSet.Get(Position)   
    Label1.Text = arvItemX.Title
    Label2.Text = arvItemX.Description

    ' Load image with Amir_Glide
    ImageView1.Tag = Null  ' needed!
    LoadImage(ImageView1, arvItemX.ImagePath)
    
    panBack.Height = Label1.Height +Label2.Height +(Label1.Top *2)     
    Parent.Height = panBack.Height +8dip
    
End Sub

Public Sub LoadImage (Img As ImageView, ImageName As String)
    Dim Glide As Amir_Glide
    Glide.Initializer.Default
    Glide.LoadWith.URI("file:///android_asset/" & ImageName).Apply(Glide.RO.CenterCrop).Into(Img)
End Sub

It now works as expected:
20-09-_2018_18-28-17.jpg


It is interesting to note that very fast scrolling has no bucking or delaying at all.

Nice Glide!​
 

Attachments

larprogramer

Member
Licensed User
Thank you. That was the needed hint to overcome the error.​



This led to the realization that images of DirAsset can be accessed as follows:
B4X:
Glide.LoadWith.URI("file:///android_asset/" & ImageName)

B4X:
Sub arv_onBindViewHolder (Parent As Panel, Position As Int)
'    Log("#-Sub arv_onBindViewHolder, Position=" & Position)
 
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    ' This fills the item content from the Dataset
    ' corresponding to the position
    ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
    Dim panBack As Panel = Parent.GetView(0)
    Dim Label1 As Label = panBack.GetView(0)
    Dim Label2 As Label = panBack.GetView(1)
    Dim ImageView1 As ImageView = panBack.GetView(2)
 
    Dim arvItemX As arvItem = DataSet.Get(Position)
    Label1.Text = arvItemX.Title
    Label2.Text = arvItemX.Description

    ' Load image with Amir_Glide
    ImageView1.Tag = Null  ' needed!
    LoadImage(ImageView1, arvItemX.ImagePath)
 
    panBack.Height = Label1.Height +Label2.Height +(Label1.Top *2)  
    Parent.Height = panBack.Height +8dip
 
End Sub

Public Sub LoadImage (Img As ImageView, ImageName As String)
    Dim Glide As Amir_Glide
    Glide.Initializer.Default
    Glide.LoadWith.URI("file:///android_asset/" & ImageName).Apply(Glide.RO.CenterCrop).Into(Img)
End Sub

It now works as expected:
View attachment 72415

It is interesting to note that very fast scrolling has no bucking or delaying at all.

Nice Glide!​
why when i debug this it nothing?
 

Attachments

Top