我正在使用OrmLite 4.47.我遵循了许多教程,并在stackoverflow上阅读了其他问题,但我无法理解如何解决这个问题.
这是完整的信息
05-15 16:36:13.805: E/AndroidRuntime(15382): Caused by: java.lang.IllegalStateException: Could not find public constructor that has a single (Context) argument for helper class class com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
05-15 16:36:13.805: E/AndroidRuntime(15382): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context]
Run Code Online (Sandbox Code Playgroud)
那是我的databaseHelper类
public class MyDatabaseHelper extends OrmLiteSqliteOpenHelper {
// name of the database file for your application -- change to something
// appropriate for your app
private static final String DATABASE_NAME = "databas.db";
// any time you make changes to your database, you may have to increase the
// database version
private static final int DATABASE_VERSION = 1;
//genera molte eccezioni
private Dao<Truck, Integer> truckDao = null;
//genera una sola eccezione a runtime
private RuntimeExceptionDao<Truck, Integer> truckRuntimeDao=null;
public MyDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
// TODO Auto-generated method stub
try {
TableUtils.clearTable(connectionSource, Truck.class);
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int OldVersion,
int newVersion) {
// TODO Auto-generated method stub
try {
TableUtils.dropTable(connectionSource, Truck.class, true);
onCreate(database,connectionSource);
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Dao<Truck, Integer> getTruckDao() throws java.sql.SQLException{
if(truckDao==null){
truckDao=getDao(Truck.class);
}
return truckDao;
}
public RuntimeExceptionDao<Truck, Integer> getTruckRuntimeExceptionDao(){
if(truckRuntimeDao==null){
truckRuntimeDao=getRuntimeExceptionDao(Truck.class);
}
return truckRuntimeDao;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这样做时,我遇到了问题
MyDatabaseHelper helper = OpenHelperManager.getHelper(this,MyDatabaseHelper.class);
RuntimeExceptionDao<Truck, Integer> truckDao = helper.getTruckRuntimeExceptionDao();
Run Code Online (Sandbox Code Playgroud)
因此数据库助手类是公共的,Activity类扩展了Activiy.
对于那些在启用minify(proguard)时遇到此错误的人:
为ormlite添加以下配置:
# ormlite
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
-keepclassmembers class * {
public <init>(android.content.Context);
}
Run Code Online (Sandbox Code Playgroud)
另外检查一下Stackoverflow - proguard-with-ormlite-on-android
| 归档时间: |
|
| 查看次数: |
3510 次 |
| 最近记录: |