Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - This Class Should Provide a Default Constructor

Tags:

java

android

When i want to Generate Signed app it tells me :

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

My Project :

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

Note: It works fine when debugging on my android device but i cant

Build > Generate Signed app

I Really don't know what to do.

Thanks ,

like image 799
Disco4uf Avatar asked Aug 23 '26 02:08

Disco4uf


2 Answers

Check by mistake you have added that adapter name in Android Manifest. If yes, remove that and try.

like image 121
Raghavendra Avatar answered Aug 24 '26 14:08

Raghavendra


A default constructor is a constructor for a class which has no arguments and can be used implicitly.

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

But in your case - this must not be the issue. The issue is that you have this class somewhere in your XML configuration where some framework is trying to instantiate it using a default constructor, while we obviously see that you need to pass 2 parameters to your constructor for the class instance to function.

like image 31
Zilvinas Avatar answered Aug 24 '26 16:08

Zilvinas