2011-11-25 4 views
7

Ho cercato di utilizzare l'esempio HelloAndroid per ORMLite ma non sono riuscito a compilare correttamente. Sto avendo un problema con la classe DatabaseHelper. Specificamente il metodo getDao():Gli esempi ORMLite per Android non verranno compilati

/** 
* Returns the Database Access Object (DAO) for our SimpleData class. 
* It will create it or return the cached value. 
*/ 
public Dao<SimpleData, Integer> getDao() throws SQLException { 
    if (simpleDao == null) { 
    simpleDao = getDao(SimpleData.class); 
    } 
    return simpleDao; 
} 

Ecco l'errore di tempo di compilazione che sto ricevendo:

parametri di tipo D non può essere determinato; esiste alcuna istanza massimale unico per il tipo D variabile con limiti superiori com.j256.ormlite.dao.Dao, com.j256.ormlite.dao.Dao

+4

Sembra molto simile al seguente [bug] (https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379). La compilazione funziona in eclissi, ma non con il normale compilatore java a causa di un problema di inferenza di tipo. Come stai compilando il codice? – CamilleLDN

+1

Sto usando IntelliJ IDE da JetBrains in esecuzione su Ubuntu 10. – curtisthibault

+0

Sono d'accordo con te @Mademoiselle Geek (nome cool). Hey curtisthibault, quale versione di Java stai usando su Ubuntu. Sembra che questo sia stato risolto in 6u24-rev (b22) e 6u25 (b01). – Gray

risposta

7

ho ottenuto un errore simile quando si cerca di costruire il mio progetto ormlite usando Netbeans:

compilazione 15 file di origine in ~/NetBeansProjects/Main/build/classes Main.java:74: parametri di tipo di D non possono essere determinati; non esiste un'istanza massima unica per la variabile di tipo D con limiti superiori com.j256.ormlite.dao.Dao, com.j256.ormlite.dao.Dao pcDao = DaoManager.createDao (connectionSource, PC.class);

A causa dei commenti ho passato la mia piattaforma Java da OpenJDK 1.6 a Oracle JDK 1.7.0_02 e ho risolto il problema.

0

La mia soluzione:

public class HelloAndroid extends OrmLiteBaseActivity<DatabaseHelper> 
{ 
    private final String LOG_TAG = getClass().getSimpleName(); 

    /** 
    * Called when the activity is first created. 
    */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     Log.i(LOG_TAG, "creating " + getClass() + " at " + System.currentTimeMillis()); 
    TextView tv = new TextView(this); 
     doSampleDatabaseStuff("onCreate", tv); 
     setContentView(tv); 
    } 

    /** 
    * Do our sample database stuff. 
    */ 
    private void doSampleDatabaseStuff(String action, TextView tv) 
    { 
     // get our dao 
     RuntimeExceptionDao<SimpleData, Integer> simpleDao = getHelper().getSimpleDataDao(); 
     // query for all of the data objects in the database 
     List<SimpleData> list = simpleDao.queryForAll(); 
     // our string builder for building the content-view 
     StringBuilder sb = new StringBuilder(); 
     sb.append("got ").append(list.size()).append(" entries in ").append(action).append("\n"); 

     // if we already have items in the database 
     int simpleC = 0; 
     for (SimpleData simple : list) 
     { 
      sb.append("------------------------------------------\n"); 
      sb.append("[").append(simpleC).append("] = ").append(simple).append("\n"); 
      simpleC++; 
     } 
     sb.append("------------------------------------------\n"); 
     for (SimpleData simple : list) 
     { 
      simpleDao.delete(simple); 
      sb.append("deleted id ").append(simple.id).append("\n"); 
      Log.i(LOG_TAG, "deleting simple(" + simple.id + ")"); 
      simpleC++; 
     } 

     int createNum; 
     do 
     { 
      createNum = new Random().nextInt(3) + 1; 
     } 
     while (createNum == list.size()); 
     for (int i = 0; i < createNum; i++) 
     { 
      // create a new simple object 
      long millis = System.currentTimeMillis(); 
      SimpleData simple = new SimpleData(millis); 
      // store it in the database 
      simpleDao.create(simple); 
      Log.i(LOG_TAG, "created simple(" + millis + ")"); 
      // output it 
      sb.append("------------------------------------------\n"); 
      sb.append("created new entry #").append(i + 1).append(":\n"); 
      sb.append(simple).append("\n"); 
      try 
      { 
       Thread.sleep(5); 
      } 
      catch (InterruptedException e) 
      { 
       // ignore 
      } 
     } 
     tv.setText(sb.toString()); 
     Log.i(LOG_TAG, "Done with page at " + System.currentTimeMillis()); 
    } 
} 
+4

Qual è la soluzione? Cosa hai cambiato nell'esempio per rispondere alla domanda di @ curtisthibault? Puoi spiegarlo un po 'di più per favore? – Gray