android - Unable to start service when service in separate package -


if problem appreciate it.

i have activity starting service using alarmmanager , works fine. created new service (a modified copy) , giving error: java.lang.runtimeexception: unable start service...with intent {...(has extras) }: java.lang.classcastexception

i've done lot of searching , have checked manifest many times seems usual problem. both services declared, inside application tags , scoped. examples i've seen refer 1 service so, in case, i've tried several different ways code 2 services in manifest have found no valid version other 1 below.

i've tried several ways create intent assume problem lies in fact new service in different package (within same app).

i tried intent filter , custom action (see bottom) gave same error.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="couk.jit.currencycheck1" android:versioncode="1" android:versionname="1.0.1" >  <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="16" />  <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="couk.jit.currencycheck1.mainmenu" ...         </activity>      <service         android:name="couk.jit.currencycheck1.serviceclass"         android:enabled="true" />     <service         android:name="couk.jit.currencycheck1.xml.serviceclassxml"         android:enabled="true" />      <activity         android:name="couk.jit.currencycheck1.historyactivity"         android:label="@string/title_activity_history" >     </activity> </application> </manifest> 

this version of activity code gives error.

import couk.jit.currencycheck1.xml.serviceclassxml; ... intent intent; if (datasource == 0 || datasource == 1) intent = new intent(this, serviceclass.class); else { intent = new intent(this, serviceclassxml.class);   //gives error } pendingintent pintent = pendingintent.getservice(this, 0, intent, 0); alarmmanager alarm = (alarmmanager) getsystemservice(context.alarm_service); alarm.setrepeating(alarmmanager.rtc_wakeup, schedulestart.gettimeinmillis(), 60 * 1000, pintent); 

these 2 versions not give error - service isn't reached. no log message, no action. (a)

//intent = new intent(this, serviceclassxml.class); //gives error intent = new intent("couk.jit.currencycheck1.xml.serviceclassxml");  

(b)

//intent = new intent(this, serviceclassxml.class); //gives error //intent = new intent("couk.jit.currencycheck1.xml.serviceclassxml"); intent = new intent(); intent.setcomponent(new    componentname("couk.jit.currencycheck1.xml","serviceclassxml.java")); 

also tried this, gives same error.

intent = new intent(context, serviceclassxml.class); 

service class

public class serviceclassxml extends service { sharedpreferences prefs = null;  @override public int onstartcommand(intent intent, int flags, int startid) {     log.i("dbg", "serviceclassxml started");     prefs =   preferencemanager.getdefaultsharedpreferences(this.getapplication().getapplicationcontext());     boolean run = prefs.getboolean("running", false);     if (!run)         stopself();     else {         new getxmltask(this.getapplication().getapplicationcontext(),  true).execute("");     }     return super.onstartcommand(intent, flags, startid); } @override public ibinder onbind(intent arg0) {     // todo auto-generated method stub     return null; } } 

attempt intent filter , custom action. manifest

    <service         android:name="couk.jit.currencycheck1.xml.serviceclassxml"         android:enabled="true" >         <intent-filter>         <action android:name="couk.jit.currencycheck1.xml.do_custom_action"/>         </intent-filter>     </service> 

activity

//intent = new intent(this, serviceclassxml.class);  //intent = new intent("couk.jit.currencycheck1.xml.serviceclassxml"); //intent = new intent(); //intent.setcomponent(new  componentname("couk.jit.currencycheck1.xml","serviceclassxml.java")); //service not reached intent = new intent("couk.jit.currencycheck1.xml.do_custom_action"); intent.setclass(this, serviceclassxml.class); 

logcat

09-03 16:56:32.344: e/androidruntime(763): fatal exception: main 09-03 16:56:32.344: e/androidruntime(763): java.lang.runtimeexception: unable start  service couk.jit.currencycheck1.xml.serviceclassxml@4602fc38 intent { flg=0x4 cmp=couk.jit.currencycheck1/.xml.serviceclassxml (has extras) }: java.lang.classcastexception: android.app.application 09-03 16:56:32.344: e/androidruntime(763):  @ android.app.activitythread.handleserviceargs(activitythread.java:3063) 09-03 16:56:32.344: e/androidruntime(763):  @ android.app.activitythread.access$3600(activitythread.java:125) 09-03 16:56:32.344: e/androidruntime(763):  @ android.app.activitythread$h.handlemessage(activitythread.java:2096) 09-03 16:56:32.344: e/androidruntime(763):  @ android.os.handler.dispatchmessage(handler.java:99) 09-03 16:56:32.344: e/androidruntime(763):  @ android.os.looper.loop(looper.java:123) 09-03 16:56:32.344: e/androidruntime(763):  @ android.app.activitythread.main(activitythread.java:4627) 09-03 16:56:32.344: e/androidruntime(763):  @ java.lang.reflect.method.invokenative(native method) 09-03 16:56:32.344: e/androidruntime(763):  @ java.lang.reflect.method.invoke(method.java:521) 09-03 16:56:32.344: e/androidruntime(763):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 09-03 16:56:32.344: e/androidruntime(763):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 09-03 16:56:32.344: e/androidruntime(763):  @ dalvik.system.nativestart.main(native method) 09-03 16:56:32.344: e/androidruntime(763): caused by: java.lang.classcastexception: android.app.application 09-03 16:56:32.344: e/androidruntime(763):  @ couk.jit.currencycheck1.xml.getxmltask.<init>(getxmltask.java:52) 09-03 16:56:32.344: e/androidruntime(763):  @ couk.jit.currencycheck1.xml.serviceclassxml.onstartcommand(serviceclassxml.java:24) 09-03 16:56:32.344: e/androidruntime(763):  @ android.app.activitythread.handleserviceargs(activitythread.java:3053) 09-03 16:56:32.344: e/androidruntime(763):  ... 10 more 

bit bullet , merged packages 1 - , still got error! know line causing problem (though don't yet know why), i'm closing question isn't right question , don't want waste people's time.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -