Android - 此类应提供默认构造函数

时间:2017-09-06 05:34:36

标签: java android

当我想生成签名应用时,它会告诉我:

   Error:Error: This class should provide a default constructor (a public constructor with no arguments) (com.example.discopc.beautiyuser.Customy) [Instantiatable]

我的项目:

public class Customy extends ArrayAdapter<String> {

private final Activity context;
        View v;
private final String[]name;

public Customy(Activity context, String[] name){
        //super(null,0);
        super(context,R.layout.activity_customy,name);


        this.context=context;
        this.name=name;



        }


public View getView(final int position,View convertView,ViewGroup parent){
        try{



        LayoutInflater infalter=context.getLayoutInflater();
        v=infalter.inflate(R.layout.activity_customy,null,true);
                TextView txtName=(TextView)v.findViewById(R.id.name);


        txtName.setText(""+name[position]+"");

        }catch(Exception e){

        }
        return v;
        }
}

注意:在我的Android设备上调试时它可以正常工作但我不能

构建&gt;生成已签名的应用

我真的不知道该怎么做。

谢谢,

2 个答案:

答案 0 :(得分:1)

默认构造函数是一个类的构造函数,它没有参数,可以隐式使用。

public Customy( /* notice - no arguments */) {
    // your code here
}

但在你的情况下 - 这绝不是问题。问题是你在XML配置中的某个地方有一个类,其中一些框架试图使用默认构造函数实例化它,而我们显然需要将2个参数传递给构造函数以使类实例起作用。

答案 1 :(得分:1)

错误地检查您是否在Android Manifest中添加了适配器名称。如果是,请删除并尝试。

相关问题