Java 错误:此类应提供默认构造函数(没有参数的公共构造函数)

Java 错误:此类应提供默认构造函数(没有参数的公共构造函数),java,android,default-constructor,Java,Android,Default Constructor,当我要构建我的项目时,它会给出这个错误消息 Error:Error:此类应提供默认构造函数(不带参数的公共构造函数)(status.PURPLE.sameera.phonestatus.ExpandableListAdapter)[可实例化] 我可以使用USB调试运行应用程序,没有任何错误。但是,当我构建APK时会发生错误 这是ExpandableListAdapter.java public class ExpandableListAdapter extends BaseExpandableL

当我要构建我的项目时,它会给出这个错误消息

Error:Error:此类应提供默认构造函数(不带参数的公共构造函数)(status.PURPLE.sameera.phonestatus.ExpandableListAdapter)[可实例化]

我可以使用USB调试运行应用程序,没有任何错误。但是,当我构建APK时会发生错误

这是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;
    }
}

您必须提供默认的
super()
,并更改适配器的名称,因为android中已经有。假设您将
适配器类重命名为
CustomExpandableListAdapter
。所以,构造函数应该是

public CustomExpandableListAdapter(Context context, List<String> listDataHeader,
                             HashMap<String, List<String>> listChildData) {
    super();
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}
公共CustomExpandableListAdapter(上下文,列表listDataHeader, HashMap listChildData){ 超级(); 这._context=context; 这。_listDataHeader=listDataHeader; 这。_listDataChild=listChildData; }

当我在android studio中创建活动类时,我遇到了这个错误,默认情况下,在android清单中自动添加了一个活动标记,而理想情况下,我应该创建/使用java类

我通过转到我的Android清单文件并删除
ViewPagerAdapter
activity标签解决了这个问题

但是“我可以使用USB调试运行应用程序而不会出现任何错误。但是,当我构建APK时会发生错误。”它仍然提供错误信息。是的,我可以运行应用程序。但当我构建apk时,它会提供errorpost full
堆栈跟踪
错误与你在问题中提到的错误无关。尝试在真实设备中运行,但应用程序在设备中运行。它没有构建apk
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)
public CustomExpandableListAdapter(Context context, List<String> listDataHeader,
                             HashMap<String, List<String>> listChildData) {
    super();
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}
Error:Error: This class should provide a default constructor  public constructor with no arguments) ViewPagerAdapter) [Instantiatable]