2013-09-16 11 views
5

पर डाला नहीं जा सकता है, मैं ओआरएमलाइट को विचलित कर रहा हूं। तो, मैं इस डीएओ फैक्टरी वर्ग"एंड्रॉइड.एप.एप्लिकेशंस के साथ एप्लिकेशन क्रैश"

public class DtoFactory extends Application { 

    private SharedPreferences preferences; 
    private DatabaseHelper databaseHelper = null; 

    private Dao<ReleveEntity, Integer> releveDAO = null; 

    @Override 
    public void onCreate() { 
      super.onCreate(); 
      preferences = PreferenceManager.getDefaultSharedPreferences(this); 
      databaseHelper = new DatabaseHelper(this); 
    } 

    public SharedPreferences getPreferences() {return preferences;} 

    public Dao<ReleveEntity, Integer> getReleveDao() throws SQLException, java.sql.SQLException { 
      if (releveDAO == null) { 
       releveDAO = databaseHelper.getDao(ReleveEntity.class); 
      } 
      return releveDAO; 
    } 

    @Override 
    public void onTerminate() { 
      super.onTerminate(); 
      if (databaseHelper != null) { 
        OpenHelperManager.releaseHelper(); 
        databaseHelper = null; 
      } 
    } 
} 

है और मुख्य में, मैं सिर्फ यह लाइनों दिखाता हूँ जहाँ मैं समस्या है:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    dtoFactory = (DtoFactory) getApplication(); 

और Manifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.exercice.ftouzi.ReleveActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name="com.exercice.ormdatabase.DtoFactory" > 
    </activity> 
</application> 
कर सकते हैं

E/AndroidRuntime(19672): FATAL EXCEPTION: main 
E/AndroidRuntime(19672): java.lang.RuntimeException: Unable to start activity 
     ComponentInfo{com.formation.adapter/com.exercice.ftouzi.ReleveActivity}: 
     java.lang.ClassCastException: android.app.Application cannot be cast to 
     com.exercice.ormdatabase.DtoFactory 

आप:

संदेश त्रुटि है कृपया इसे हल करने में मेरी मदद करें?

+0

समस्या है संदेश का कहना है बस के रूप में, आप android.app.Application कास्ट करने के लिए com.exercice की कोशिश कर रहे में .ormdatabase.DtoFactory, और यह विफल रहता है। DtoFactory android.app.Aplication का उप-वर्ग है, इसलिए आप dtoFactory ऑब्जेक्ट्स को android.app.Aplication पर डाले जा सकते हैं, लेकिन इसके विपरीत नहीं। इसके बारे में सोचें, गायब जानकारी कहां से आएगी? – bgse

उत्तर

29

आप अपने कस्टम निर्दिष्ट करने की आवश्यकता Application (यानी, DtoFactory) AndroidManifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" 
    android:name="com.exercice.ormdatabase.DtoFactory"> 
    <activity 
     android:name="com.exercice.ftouzi.ReleveActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
+0

मैंने यह किया, मैंने अपना manifest.xml रखा और मैं –

+0

पर काम नहीं कर रहा हूं आपने इसे 'गतिविधि' के रूप में शामिल किया है, लेकिन आपको इसे 'एप्लिकेशन' के रूप में निर्दिष्ट करने की आवश्यकता है। अद्यतन उत्तर की जांच करें। – Rajesh

+1

आपने मेरी जान बचाई! धन्यवाद सर –

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