当前位置: 代码迷 >> Android >> 不兼容的类型:推断的类型不符合推断的上限:Dao 上限
  详细解决方案

不兼容的类型:推断的类型不符合推断的上限:Dao 上限

热度:52   发布时间:2023-08-04 10:21:39.0

我正在Android Studio项目上的现有数据库上实现ORMLite ...已完成,但是现在我正在进行升级,因为我正在使用DAO,但出现此错误:

错误:(67,68)错误:不兼容的类型:推断的类型不符合推断的上限:Dao上限:Dao,Dao

错误:任务':app:compileDebugJavaWithJavac'的执行失败。 编译失败; 有关详细信息,请参见编译器错误输出。

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {


    private static final int DATABASE_VERSION = ...;
    private static final String DATABASE_NAME = "...";
    public SQLiteDatabase sqLiteDatabase;
    private Context mContext;
    Dao<Account, String> daoDemandes;



    private static final String TABLE_DEMANDES = "demandes";
    private static final String KEY_ID = "id";
    private static final String KEY_XML_SENDLEAD = "xmlSendLead";
    private static final String KEY_STATUTENVOIE_SENDLEAD = "statutEnvoieSendLead";
    private static final String KEY_DATEENVOIE_SENDLEAD = "dateEnvoieSendLead";
    private static final String KEY_CONTACTWEBID = "contactWebId";
    private static final String KEY_XML_SIMULATION = "xmlSimulation";
    private static final String KEY_STATUTENVOIE_SIMULATION = "statutEnvoieSimulation";
    private static final String KEY_DATEENVOIE_SIMULATION = "dateEnvoieSimulation";



    private Dao<Demandes, Integer> simpleDao = null;
    private RuntimeExceptionDao<Demandes, Integer> simpleRuntimeDao = null;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
    }


    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource){
        try {
            TableUtils.createTable(connectionSource, Demandes.class);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
        try {

            Dao<Account, String> daoDemandes = DaoManager.createDao(connectionSource, Demandes.class);


            if (oldVersion < 4) {
                daoDemandes.executeRaw("ALTER TABLE " + TABLE_DEMANDES + " RENAME TO demandes2");
                daoDemandes.executeRaw("CREATE TABLE " + TABLE_DEMANDES + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_XML_SENDLEAD + " TEXT," + KEY_STATUTENVOIE_SENDLEAD + " INTEGER," + KEY_DATEENVOIE_SENDLEAD + " DATETIME," + KEY_CONTACTWEBID + " INTEGER," + KEY_XML_SIMULATION + " TEXT," + KEY_STATUTENVOIE_SIMULATION + " INTEGER," + KEY_DATEENVOIE_SIMULATION + " DATETIME" + ")");
                daoDemandes.executeRaw("INSERT INTO " + TABLE_DEMANDES + " (" + KEY_ID + "," + KEY_XML_SENDLEAD + "," + KEY_STATUTENVOIE_SENDLEAD + "," + KEY_DATEENVOIE_SENDLEAD + ")" + " SELECT id, xml, statutEnvoie, dateEnvoie" + " FROM demandes2;");
                daoDemandes.executeRaw("DROP TABLE demandes2");
                System.out.println("v4 parsed");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
  Dao<Account, String> daoDemandes = DaoManager.createDao(connectionSource, Demandes.class); 

您正在尝试创建Dao<Account,String>但是正在为类Demandes创建一个DAO。 应该是:

Dao<Demandes, String> daoDemandes = DaoManager.createDao(connectionSource, Demandes.class);

其中的String应该是Demandes的id类型,可以是LongInteger

您应该可以自己解决此问题。 也许您需要更多地了解 ? 调试代码时,您应该能够通过仔细查看引起异常的行来评估问题。

另一尝试是从daoDemandes之前删除类型规范,并允许您的IDE自行生成它。 那本来可以。

  相关解决方案