Jitin Jassal
Jitin Jassal

Reputation: 137

Error building signed apk in android studio: This class should provide default constructor

Error: This class should provide a default constructor (a public constructor with no arguments) (com.tasbih.counter.tasbihcounter.RegistrationAdapterr) [Instantiatable]

This error occurs when i try to build signed apk, but in debug mode the app is working fine. Please help.

package com.tasbih.counter.tasbihcounter;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

    public class RegistrationAdapterr {
    SQLiteDatabase database_ob;
    RegistrationOpenHelperr openHelper_ob;
    Context context;

    public RegistrationAdapterr(Context c) {
        context = c;
    }


    public RegistrationAdapterr opnToRead() {
        openHelper_ob = new RegistrationOpenHelperr(context,
                openHelper_ob.DATABASE_NAME, null, openHelper_ob.VERSION);
        database_ob = openHelper_ob.getReadableDatabase();
        return this;
    }

    public RegistrationAdapterr opnToWrite() {
        openHelper_ob = new RegistrationOpenHelperr(context,
                openHelper_ob.DATABASE_NAME, null, openHelper_ob.VERSION);
        database_ob = openHelper_ob.getWritableDatabase();
        return this;
    }

    public void Close() {
        database_ob.close();
    }

    public long insertDetails(String fname, String lname, Integer count) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(openHelper_ob.FNAME, fname);
        contentValues.put(openHelper_ob.LNAME, lname);
        contentValues.put(openHelper_ob.COUNT, count);
        opnToWrite();
        long val = database_ob.insert(openHelper_ob.TABLE_NAME, null,
                contentValues);
        Close();
        return val;
    }

    public Cursor queryName() {
        String[] cols = {openHelper_ob.KEY_ID, openHelper_ob.FNAME,
                openHelper_ob.LNAME, openHelper_ob.COUNT};
        opnToWrite();
        Cursor c = database_ob.query(openHelper_ob.TABLE_NAME, cols, 
                null, null, null, null, null);
        return c;
    }

    public Cursor queryAll(int nameId) {
        String[] cols = {openHelper_ob.KEY_ID, openHelper_ob.FNAME,
                openHelper_ob.LNAME, openHelper_ob.COUNT};
        opnToWrite();
        Cursor c = database_ob.query(openHelper_ob.TABLE_NAME, cols,
                openHelper_ob.KEY_ID + "=" + nameId, null, null, null, null);
        return c;
    }

    public long updateldetail(int rowId, String fname, String lname, Integer count) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(openHelper_ob.FNAME, fname);
        contentValues.put(openHelper_ob.LNAME, lname);
        contentValues.put(openHelper_ob.COUNT, count);
        opnToWrite();
        long val = database_ob.update(openHelper_ob.TABLE_NAME, contentValues,
                openHelper_ob.KEY_ID + "=" + rowId, null);
        Close();
        return val;
    }

    public int deletOneRecord(int rowId) {
        // TODO Auto-generated method stub
        opnToWrite();
        int val = database_ob.delete(openHelper_ob.TABLE_NAME,
                openHelper_ob.KEY_ID + "=" + rowId, null);
        Close();
        return val;
    }
}

Upvotes: 1

Views: 2482

Answers (3)

drunkZombie
drunkZombie

Reputation: 163

Add this in your class:

public RegistrationAdapterr(){}

to => public class RegistrationAdapterr

and

public RegestrationOpenHelper(Context context) {
    super(context, DB_Name, null, DB_Ver);
}

to => class RegestrationOpenHelper

Upvotes: 0

codezjx
codezjx

Reputation: 9142

I think you should try to add following script in you build.gradle. (Must write in android{} tag)

lintOptions {
    abortOnError false
}

When your release build generate an error by lint, the build task will not abort.

Upvotes: 4

Rahul Sharma
Rahul Sharma

Reputation: 6179

Add this in your class:

public RegistrationAdapterr(){
}

In which class you find same error, just create default constructor, like for RegestrationOpenHelper:

public RegestrationOpenHelper(){
}

Upvotes: 0

Related Questions