2011-11-25 3 views
7

मैं उदाहरण ORMLite के लिए उदाहरण के लिए काम करने का प्रयास कर रहा हूं लेकिन सफलतापूर्वक संकलित करने में सक्षम नहीं हूं। मुझे डेटाबेसहेल्पर क्लास में समस्या है। विशेष रूप से getDao() विधि:एंड्रॉइड के लिए ORMLite उदाहरण संकलित नहीं करेंगे

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

यहाँ संकलन समय त्रुटि मैं प्राप्त कर रहा है:

डी के

प्रकार पैरामीटर निर्धारित नहीं किया जा सकता है; कोई अद्वितीय अधिक से अधिक उदाहरण के लिए ऊपरी सीमा com.j256.ormlite.dao.Dao साथ प्रकार चर डी मौजूद है, com.j256.ormlite.dao.Dao

+4

यह निम्न [बग] (https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379) जैसा दिखता है। संकलन ग्रहण में काम करता है, लेकिन सामान्य जावा कंपाइलर के साथ एक प्रकार की अनुमान समस्या के कारण नहीं। आप कोड कैसे संकलित कर रहे हैं? – CamilleLDN

+1

मैं उबंटू 10 में चल रहे जेटब्रेन से इंटेलिजे आईडीई का उपयोग कर रहा हूं। – curtisthibault

+0

मैं आपके साथ @Mademoiselle Geek (ठंडा नाम) से सहमत हूं। अरे curtisthibault, जावा के किस संस्करण का उपयोग आप अपने उबंटू पर कर रहे हैं। ऐसा लगता है कि यह 6u24-rev (बी 22) और 6u25 (बी 01) में तय है। – Gray

उत्तर

7

मुझे मिल गया इसी तरह की एक त्रुटि Netbeans का उपयोग कर मेरी ormlite परियोजना बनाने की कोशिश:

~/NetBeansProjects/मुख्य/निर्माण/वर्गों Main.java:74 करने के लिए 15 स्रोत फ़ाइलें संकलन: डी के प्रकार के मापदंडों का निर्धारण नहीं किया जा सकता है; ऊपरी सीमा com.j256.ormlite.dao.Dao, com.j256.ormlite.dao.Dao पीसीडीओ = दाओमेनगर.क्रेटडाओ (कनेक्शनसोर्स, पीसी.क्लास) के साथ टाइप वैरिएबल डी के लिए कोई अद्वितीय अधिकतम उदाहरण मौजूद नहीं है;

टिप्पणियों के कारण मैंने अपने जावा प्लेटफ़ॉर्म को ओपनजेडीके 1.6 से ओरेकल के जेडीके 1.7.0_02 पर स्विच किया और इसने समस्या को हल किया।

0

मेरे समाधान:

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

समाधान क्या है? @ Curtisthibault के प्रश्न का उत्तर देने के लिए उदाहरण में आपने क्या बदल दिया? क्या आप इसे थोड़ा और समझ सकते हैं? – Gray

संबंधित मुद्दे