以下のクラスで gridview を宣言すると、さまざまなエラーが発生します。
class LoadAllProducts extends Activity //get call on dynamic btn action
{
public void onCreate() {
System.out.println("I have enterd in external class");
// ***GridView gridView3 = (GridView) findViewById(R.id.gridview3);***//cant declare getting error
ArrayList mButtons3 = new ArrayList(); //to print button dynamically on gridview
Button cb3; //=new Button(this); if do so getting error
JSONObject json2 = null;
json2 = jParser.makeHttpRequest(url_all_products, "GET", params);
// System.out.println("success to get json object for all products/t"+json2);// getting data from php an mysql database
JSONArray products2 = null;
String[] Itemname = null;
String[] rcatacode = null;
try {
int success2 = json2.getInt(TAG_ALLPRODUCT_SUCCESS);
products2 = json2.getJSONArray(TAG_ALLPRODUCT_PRODUCTS);
Itemname = new String[products2.length()];
rcatacode = new String[products2.length()];
if (success2 == 1) {
cb3 = new Button(this);
for (int i = 0; i < products2.length(); i++) {
JSONObject c = products2.getJSONObject(i);
// Storing each json item in variable
String itemcode = c.getString(TAG_ALLPRODUCT_MCODE); //to store data from database
String itemname = c.getString(TAG_ALLPRODUCT_ITEM_NAME);
String item_rate = c.getString(TAG_ALLPRODUCT_RATE);
String r_cata = c.getString(TAG_ALLPRODUCT_RCATA);
Itemname[i] = itemname;
rcatacode[i] = r_cata;
}
}
} // try closed
catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < 20; i++) {
// Button b=new Button(this); //getting error on here also
System.out.println(Itemname[i]);
}
}
}