Rec
Rec

Reputation: 71

error: this class should provide a default constructor, when creating apk

I'm experiencing this error when building the apk: this class should provide a default constructor (a public constructor with no arguments)

I have searched for this error and a solution is to change the class name, I tried but the error occurs with others classes and after change the name of some classes comeback to the first one, I am in a bucle.

The first class I have the error is this

CustomaAdapter.java

public class CustomAdapter extends BaseAdapter {


// Declare Variables
Context context;
LayoutInflater inflater;
ImageLoader imageLoader;
private List<Juegos> juegoslist = null;
private ArrayList<Juegos> arraylist;


public CustomAdapter(Context context,
                     List<Juegos> juegoslist) {

    this.context = context;
    this.juegoslist = juegoslist;
    inflater = LayoutInflater.from(context);
    this.arraylist = new ArrayList<Juegos>();
    this.arraylist.addAll(juegoslist);
    imageLoader = new ImageLoader(context);

}

I can run the app in a device without problems but I can't create the apk. Someone can help me with this issue?

Thanks and regards,

Upvotes: 1

Views: 409

Answers (2)

Yuva Raj
Yuva Raj

Reputation: 3881

Simply create a empty constructor for CustomAdapter class. Your final code should be like,

public class CustomAdapter extends BaseAdapter {


// Declare Variables
Context context;
LayoutInflater inflater;
ImageLoader imageLoader;
private List<Juegos> juegoslist = null;
private ArrayList<Juegos> arraylist;

// empty constructor
public CustomAdapter() {

} 

public CustomAdapter(Context context,
                     List<Juegos> juegoslist) {

    this.context = context;
    this.juegoslist = juegoslist;
    inflater = LayoutInflater.from(context);
    this.arraylist = new ArrayList<Juegos>();
    this.arraylist.addAll(juegoslist);
    imageLoader = new ImageLoader(context);

}

Upvotes: 0

GustavoCinque
GustavoCinque

Reputation: 166

When you override the constructor, the class understand that it doesn't exist anymore, because you are only defining the modified one. To resolve it just place an empty constructor in the class:

public CustomAdapter(){}

Upvotes: 1

Related Questions