1

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;
    }
}
beresfordt
  • 5,088
  • 10
  • 35
  • 43
Jitin Jassal
  • 137
  • 2
  • 13
  • Best Solution worked for me add files in gradle hope it works.[Check this](http://stackoverflow.com/questions/17420637/error-non-default-constructors-in-fragments/39608360#39608360) – Naeem Ibrahim Sep 21 '16 at 05:46

3 Answers3

4

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.

codezjx
  • 9,012
  • 5
  • 47
  • 57
0

Add this in your class:

public RegistrationAdapterr(){
}

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

public RegestrationOpenHelper(){
}
Rahul Sharma
  • 5,949
  • 5
  • 36
  • 46
  • It is showing the same error in RegestrationOpenHelper.java now, but error from RegistrationAdapterr is solved public class RegistrationOpenHelperr extends SQLiteOpenHelper { public RegistrationOpenHelperr(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } – Jitin Jassal Mar 14 '15 at 09:22
  • When i created public RegestrationOpenHelper() {} in RegestrationOpenHelper.java It is showing this error Error:(22, 5) error: no suitable constructor found for SQLiteOpenHelper(no arguments) constructor SQLiteOpenHelper.SQLiteOpenHelper(Context,String,CursorFactory,int) is not applicable (actual and formal argument lists differ in length) constructor SQLiteOpenHelper.SQLiteOpenHelper(Context,String,CursorFactory,int,DatabaseErrorHandler) is not applicable (actual and formal argument lists differ in length) – Jitin Jassal Mar 14 '15 at 09:31
  • same error: i am creating the constructor with no arguments – Jitin Jassal Mar 14 '15 at 09:38
  • The error occurs only when i try to generate signed APK. http://postimg.org/image/81ydc3gkt/ – Jitin Jassal Mar 14 '15 at 09:51
  • ok, then make default constructor in all those classes for which you see this error. – Rahul Sharma Mar 14 '15 at 10:12
  • can u tell me how to do this in the code, in RegestrationOpenHelperr.java http://pastebin.com/mbBNjeAK – Jitin Jassal Mar 14 '15 at 10:35
  • for those classes for which you see this error, put the above method(which i put in answer) and replace the method name with class name – Rahul Sharma Mar 14 '15 at 10:41
  • same error (Error:(22, 5) error: no suitable constructor found for SQLiteOpenHelper(no arguments) constructor SQLiteOpenHelper.SQLiteOpenHelper(Context,String,CursorFactory,int) is not applicable (actual and formal argument lists differ in length) constructor SQLiteOpenHelper.SQLiteOpenHelper(Context,String,CursorFactory,int,DatabaseErrorHandler) is not applicable (actual and formal argument lists differ in length)) in RegestrationOpenHelperr.java – Jitin Jassal Mar 14 '15 at 10:43
0

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

drunkZombie
  • 112
  • 2
  • 15