Array becoming null
-
I am creating some push buttons (say valves) and adding them in an array and then displaying them in a grid layout. When I move to the next page, I delete the current array and then repopulate it. But when I am trying to access it, it is becoming a nullpointer. So, basically the valves are visible on the next page, but I am unable to access them. What would be the solution for it?
-
I am creating some push buttons (say valves) and adding them in an array and then displaying them in a grid layout. When I move to the next page, I delete the current array and then repopulate it. But when I am trying to access it, it is becoming a nullpointer. So, basically the valves are visible on the next page, but I am unable to access them. What would be the solution for it?
@shreya_agrawal said in Array becoming null:
What would be the solution for it
Don't delete the array in the first place ?
-
@shreya_agrawal said in Array becoming null:
What would be the solution for it
Don't delete the array in the first place ?
@J-Hilk
But without deleting the current array, how would I be able to display the new array when I click the next and previous buttons? -
@J-Hilk
But without deleting the current array, how would I be able to display the new array when I click the next and previous buttons?@shreya_agrawal I don't know. I can't give you more, due to a severe lack of information from your part.
-
@shreya_agrawal I don't know. I can't give you more, due to a severe lack of information from your part.
@J-Hilk
I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time. -
S shreya_agrawal has marked this topic as solved on
-
@J-Hilk
I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time.This post is deleted! -
@J-Hilk
I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time.@shreya_agrawal
This is how I did it for future reference:// First, add all valves to the array for (int i = 0; i < totalValves; ++i) { valve[i] = new Valve(this); } // Show or hide the valves according to their indexes for (int i = 0; i < totalValves; ++i) { if (valve[i] != nullptr) { if (i >= currentIndex && i < currentIndex + visibleValves) { valve[i]->show(); } else { valve[i]->hide(); } }