Android开源框架OrmLite使用出现的问题及解决方案

在初次使用ORM框架OrmLite时,遇到了构造方法调用错误的问题。博客作者详细描述了问题的现象,并分享了自己找到的解决方案,旨在帮助遇到同样问题的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚接触强大的开源框架OrmLite,介绍不是本文的主题,初学者可以参照这篇博客:http://blog.youkuaiyun.com/cjjky/article/details/7096987。我在使用时遇到一个问题,在网上搜也没有相关解决方案,故我这里说明一下,希望可以帮助到以后遇到该问题的人。

问题描述:java.lang.IllegalStateException: Could not find constructor that hast just a (Context) argument for helper class class ...(省略部分为包名+继承自OrmLiteSqliteOpenHelper的具体类名)

解决方案:

重载的构造方法调用错误,将其他重载的构造方法如:

private static final String DB_NAME = "student.db";
	private static final int VERSION = 1;
	
	private Dao<Student, Integer> studentDao = null;
	
	public DataHelper(Context context, String databaseName,
			CursorFactory factory, int databaseVersion) {
		super(context, DB_NAME, null, VERSION);
	}


替换为唯一可使用的构造方法:
private static final String DB_NAME = "student.db";
	private static final int VERSION = 1;
	
	private Dao<Student, Integer> studentDao = null;
	
	public DataHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
	}


再运行看看是否解决了上面的异常了呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值