Android的ORMLite示例不能编译

我一直在尝试通过ORA说的HelloAndroid的例子,但一直无法成功编译。 我遇到了DatabaseHelper类的问题。 特别是getDao()方法:

 /** * 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; } 

这是我收到的编译时错误:

D的types参数不能确定; typesvariablesD的上限没有唯一的最大实例com.j256.ormlite.dao.Dao,com.j256.ormlite.dao.Dao

Solutions Collecting From Web of "Android的ORMLite示例不能编译"

当我尝试使用Netbeans构build我的ormlite项目时遇到了类似的错误:

编译15个源文件到〜/ NetBeansProjects / Main / build / classes Main.java:74:无法确定D的types参数; 没有唯一的最大实例存在typesvariablesD的上限com.j256.ormlite.dao.Dao,com.j256.ormlite.dao.Dao pcDao = DaoManager.createDao(connectionSource,PC.class);

由于我的意见,我把我的Java平台从OpenJDK 1.6切换到Oracle的JDK 1.7.0_02,并解决了这个问题。

我的解决scheme

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