G grafsoft Well-Known Member Licensed User Longtime User Apr 25, 2016 #1 I have several iconbuttons and mist find the one with a certain tag. But when I want to work with it, I get "java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams com.phillipcalvin.iconbutton.IconButton.getLayoutParams()' on a null object reference" Why? Code: Dim clickedbtn as IconButton For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then t=v.Tag Log (t) If t=clickedno Then clickedbtn=v ' the next line throws the error Log (clickedbtn.Left & " - " & clickedbtn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next
I have several iconbuttons and mist find the one with a certain tag. But when I want to work with it, I get "java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams com.phillipcalvin.iconbutton.IconButton.getLayoutParams()' on a null object reference" Why? Code: Dim clickedbtn as IconButton For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then t=v.Tag Log (t) If t=clickedno Then clickedbtn=v ' the next line throws the error Log (clickedbtn.Left & " - " & clickedbtn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next
DonManfred Expert Licensed User Longtime User Apr 25, 2016 #2 v is a VIEW. Views does not have a Tag. You need to cast v to a IconButton to get the IconButtons Tag. Code: Dim clickedbtn as IconButton For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v t=btn.Tag Log (t) If t=clickedno Then clickedbtn=v ' the next line throws the error Log (clickedbtn.Left & " - " & clickedbtn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next Upvote 0
v is a VIEW. Views does not have a Tag. You need to cast v to a IconButton to get the IconButtons Tag. Code: Dim clickedbtn as IconButton For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v t=btn.Tag Log (t) If t=clickedno Then clickedbtn=v ' the next line throws the error Log (clickedbtn.Left & " - " & clickedbtn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next
G grafsoft Well-Known Member Licensed User Longtime User Apr 25, 2016 #3 Thank you, bit this did not help. The error message remains. And then, this does not work: Code: Dim bb As BitmapDrawable bb.Initialize(Basis.CreateScaledBitmap2(LoadBitmap(File.DirAssets,"ic_play_black_48dp.png"), 40dip, 40dip, True)) clickedbtn.setIcon (False,bb) It throws no error, but it does not work. If I say "clickedbtn is the newest button" - it works, but on the wrong button. Upvote 0
Thank you, bit this did not help. The error message remains. And then, this does not work: Code: Dim bb As BitmapDrawable bb.Initialize(Basis.CreateScaledBitmap2(LoadBitmap(File.DirAssets,"ic_play_black_48dp.png"), 40dip, 40dip, True)) clickedbtn.setIcon (False,bb) It throws no error, but it does not work. If I say "clickedbtn is the newest button" - it works, but on the wrong button.
DonManfred Expert Licensed User Longtime User Apr 25, 2016 #4 sorry, my code was wrong. maybe this is the problem Code: For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v t=btn.Tag Log (t) If t=clickedno Then ' the next line throws the error Log (btn.Left & " - " & btn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next Upvote 0
sorry, my code was wrong. maybe this is the problem Code: For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v t=btn.Tag Log (t) If t=clickedno Then ' the next line throws the error Log (btn.Left & " - " & btn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next
DonManfred Expert Licensed User Longtime User Apr 25, 2016 #5 grafsoft said: And then, this does not work Click to expand... This is another issue! You should start a new thread for any new question. Upvote 0
grafsoft said: And then, this does not work Click to expand... This is another issue! You should start a new thread for any new question.
G grafsoft Well-Known Member Licensed User Longtime User Apr 26, 2016 #6 Is it really? The problem is - I need to find the iconbutton with a certain tag and cast a global variable to it which I can use in another part of the program. Upvote 0
Is it really? The problem is - I need to find the iconbutton with a certain tag and cast a global variable to it which I can use in another part of the program.
DonManfred Expert Licensed User Longtime User Apr 28, 2016 #7 grafsoft said: and cast a global variable to it which Click to expand... Your code in post #1 does not tell this requirement that there is a gobal variable Create a global variable Code: Dim clickedbtn as IconButton and then you can use it like this i guess Code: For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v clickedbtn = btn t=btn.Tag Log (t) If t=clickedno Then ' the next line throws the error Log (btn.Left & " - " & btn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next If not i guess you should post a project which shows the problem. Upvote 0
grafsoft said: and cast a global variable to it which Click to expand... Your code in post #1 does not tell this requirement that there is a gobal variable Create a global variable Code: Dim clickedbtn as IconButton and then you can use it like this i guess Code: For Each v As View In Activity.GetAllViewsRecursive Try ' only check iconbuttons If v Is IconButton Then dim btn as IconButton = v clickedbtn = btn t=btn.Tag Log (t) If t=clickedno Then ' the next line throws the error Log (btn.Left & " - " & btn.Top) End If End If Catch Basis.debuginfo (LastException.Message,False) End Try Next If not i guess you should post a project which shows the problem.
G grafsoft Well-Known Member Licensed User Longtime User Apr 29, 2016 #8 Thank you Manfred! I had help and the problem was found: I created buttons on top of each other. Case closed. Upvote 0
Thank you Manfred! I had help and the problem was found: I created buttons on top of each other. Case closed.