2017-02-09 22 views
0

我在我的Android Studio項目的現有數據庫上執行ORMLite ......一切都過去了,但現在我正在升級,SI我與DAO工作,但我得到這個錯誤:不兼容的類型:推斷類型不符合上限(一個或多個)推斷:道「賬戶,String>的上限(一個或多個)

Error:(67, 68) error: incompatible types: inferred type does not conform to upper bound(s) inferred: Dao upper bound(s): Dao,Dao

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

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(); 
     } 
    } 

} 

回答

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

您正在試圖創建一個Dao<Account,String>但要創建爲A DAO類Demandes。這應該是:

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

String中應該有Demandes ID類型可以是一個LongInteger

您應該已經能夠通過自己想通這個問題了。也許你需要了解更多關於how generics work?在調試代碼時,您應該能夠通過仔細查看導致異常的行來評估問題。

另一件事,試圖將已經從daoDemandes之前刪除的型號規格,讓您的IDE自我生成它。這將會奏效。