在我的主要活动中,如果我应用此代码,我得到错误gridviewadapter() cannot be applied,
这是上下文中的问题。
GridViewAdapter adapter = new GridViewAdapter(this, R.layout.grid_item_layout, result);
如果我这样应用:
public MainActivity (Context context) {
mContext = context;
}
GridViewAdapter adapter = new GridViewAdapter(mContext, R.layout.grid_item_layout, result);
我在Logcat中发现了这个错误
java.lang.InstantiationException: can't instantiate class com.justedhak.www.i.MainActivity; no empty constructor
我正在尝试将AsyncTask ArrayList值传递给MainActivity..怎么解决?
最佳答案
不应为MainActivity
类使用构造函数。
请使用:
GridViewAdapter adapter = new GridViewAdapter(getApplicationContext(), R.layout.grid_item_layout, result);
而不是:
GridViewAdapter adapter = new GridViewAdapter(this, R.layout.grid_item_layout, result);