[英]Error: This class should provide a default constructor (a public constructor with no arguments)
When I'm going to Build my project it give this error message. 当我要构建项目时,会显示此错误消息。
Error:Error: This class should provide a default constructor (a public constructor with no arguments) (status.PURPLE.sameera.phonestatus.ExpandableListAdapter) [Instantiatable]
I can run the app with USB Debugging without any errors. 我可以使用USB调试运行该应用程序,而不会出现任何错误。 However, the error happens when I build an APK. 但是,在构建APK时会发生错误。
This is ExpandableListAdapter.java 这是ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item,null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
This is MyActivity.java 这是MyActivity.java
public class MyActivity extends ActionBarActivity {
//Listview
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
}
//preparing list data
private void prepareListData(){
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
}
Logcat logcat的
07-18 10:00:01.380 1250-1250/status.PURPLE.sameera.phonestatus W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
07-18 10:00:01.388 1250-1250/status.PURPLE.sameera.phonestatus E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache
07-18 10:00:01.396 1250-1250/status.PURPLE.sameera.phonestatus E/OpenGLRenderer﹕ MAX_TEXTURE_SIZE: 16384
07-18 10:00:01.424 1250-1250/status.PURPLE.sameera.phonestatus E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
07-18 10:00:01.432 1250-1250/status.PURPLE.sameera.phonestatus E/OpenGLRenderer﹕ MAX_TEXTURE_SIZE: 16384
07-18 10:00:09.788 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:09.892 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:09.964 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.028 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.076 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.120 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.164 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.212 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
07-18 10:00:10.260 1250-1250/status.PURPLE.sameera.phonestatus E/eglCodecCommon﹕ **** ERROR unknown type 0xfc00 (glSizeof,73)
Error:Error: This class should provide a default constructor public constructor with no arguments) ViewPagerAdapter) [Instantiatable]
I experienced this error when I created an activity class in android studio, by default an activity tag was automatically added in Android Manifest, when idealy I was supposed to create/use a java class. 我在android studio中创建活动类时遇到了此错误,默认情况下,当理想情况下应该创建/使用Java类时,会在Android Manifest中自动添加活动标签。
I solved it by going to my Android manifest file and deleting the ViewPagerAdapter
activity tag 我通过转到Android清单文件并删除ViewPagerAdapter
活动标签来解决了该问题
you have to provide default super()
and change your adapter's name because there is already ExpandableListAdapter in android. 您必须提供默认的super()
并更改适配器的名称,因为android中已经有ExpandableListAdapter了。 Suppose you rename your adapter class
to CustomExpandableListAdapter
. 假设您将adapter class
重命名为CustomExpandableListAdapter
。 So, constructor should be 因此,构造函数应为
public CustomExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
super();
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.