0

嗨,我收到错误我的 logcat 是:

08-12 12:49:07.095: E/AndroidRuntime(4151): FATAL EXCEPTION: main
08-12 12:49:07.095: E/AndroidRuntime(4151): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kns.expense.activty/com.kns.expense.activty.AddExpenseActivity}: java.lang.IllegalStateException: Could not find constructor that hast just a (Context) argument for helper class null
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.os.Looper.loop(Looper.java:137)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at java.lang.reflect.Method.invoke(Method.java:511)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at dalvik.system.NativeStart.main(Native Method)
08-12 12:49:07.095: E/AndroidRuntime(4151): Caused by: java.lang.IllegalStateException: Could not find constructor that hast just a (Context) argument for helper class null
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.j256.ormlite.android.apptools.OpenHelperManager.constructHelper(OpenHelperManager.java:210)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.j256.ormlite.android.apptools.OpenHelperManager.loadHelper(OpenHelperManager.java:165)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.j256.ormlite.android.apptools.OpenHelperManager.getHelper(OpenHelperManager.java:75)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.kns.expense.db.DatabaseManager.getHelper(DatabaseManager.java:18)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.kns.expense.db.Repo.<init>(Repo.java:13)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.kns.expense.activty.AddExpenseActivity.onCreate(AddExpenseActivity.java:48)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.Activity.performCreate(Activity.java:5104)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-12 12:49:07.095: E/AndroidRuntime(4151):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-12 12:49:07.095: E/AndroidRuntime(4151):     ... 11 more
08-12 12:49:07.095: E/AndroidRuntime(4151): Caused by: java.lang.NullPointerException
08-12 12:49:07.095: E/AndroidRuntime(4151):     at com.j256.ormlite.android.apptools.OpenHelperManager.constructHelper(OpenHelperManager.java:208)
08-12 12:49:07.095: E/AndroidRuntime(4151):     ... 19 more
08-12 12:49:10.305: D/dalvikvm(4175): GC_CONCURRENT freed 63K, 7% free 2776K/2984K, paused 74ms+3ms, total 207ms

在回购代码中调用时:

public Repo(Context context) {  {
        DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
        db = manager.getHelper(context, DatabaseHelper.class);// here getting error
        Users = new RepoUsers(db);
    }   

和 DatabaseHelper 是

public class DatabaseHelper extends OrmLiteSqliteOpenHelper{

    private static final String DATABASE_NAME = "ezexpense.sqlite";
    private static final int DATABASE_VERSION = 1;

    private Dao<EzExpenseProject, String> userDao = null;
    private RuntimeExceptionDao<EzExpenseProject, String> userRuntimeDao = null;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

        DatabaseInitializer initializer = new DatabaseInitializer(context);
        try {
            initializer.createDatabase();
            initializer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

请帮助我如何克服这个错误?

4

1 回答 1

0

有时在您的应用程序的 gradle 文件中使用 Proguard 会发生这种情况,可以通过裁判 使用 proguard for ormLite来修复

于 2019-04-30T20:47:17.800 回答