Reputation: 125
Hey guys I am building an app to show data as grid View and Grid View may be multiple its depend on Web Service data so I am using Dynamic Grid View objects As array but When I am initializing Grid View objects.. it is showing me compile time error(NULL Pointer Exception) any one have answer for this question.
public class FoodLevelPageOne extends Activity {
private Button home;
private Button back;
private LinearLayout linearLayout;
private HttpResponse httpResponse;
.....
...
private ArrayList<JsonData> al1[];
private GridView gv[];
....
....
....
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);`
...
...
gv[i] = new GridView(getApplicationContext());
Upvotes: 2
Views: 137
Reputation: 2338
You have not initialized and specified the size of the array.
You should follow these steps:
Get the size of the response of the webservice data, i.e. How many gridviews to be shown/filled.
JSONArray arrayFromWebservice = new JSONArray(webServiceResponse);
int SIZE_OF_GRID = arrayFromWebservice.length;
Now, initialize the grid array with the SIZE_OF_GRID variable.
gv = new GridView[SIZE_OF_GRID];
// do some work with the array.
Upvotes: 1
Reputation: 3627
From your code, I think that you should miss to initialize array of grid view..
private GridView gv[] = new GridView[CONTSTANT_NUMBER];
or:
You must be use collection framework Arraylist<GridView>
object to generate dynamic list.
Upvotes: 0