简体   繁体   English

java.lang.ClassCastException:android.os.ResultReceiver无法强制转换为com.hello.utils.network.MyReciever

[英]java.lang.ClassCastException: android.os.ResultReceiver cannot be cast to com.hello.utils.network.MyReciever

i am trying to use a custom ResultReciever from an intent into a intentService but i get this bizare error. 我试图使用自定义ResultReciever从intent到intentService但我得到这个bizare错误。

any ideas why? 任何想法为什么?

Followed this guide in using resulReciever as callbacks 按照本指南使用resulReciever作为回调

http://lalit3686.blogspot.co.uk/2012/06/how-to-update-activity-from-service.html http://lalit3686.blogspot.co.uk/2012/06/how-to-update-activity-from-service.html

Here is my code from activity that starts service: 这是来自启动服务的活动的代码:

private void doNetworkInitCalls() {
    intent = new Intent(getApplicationContext(), NetworkService.class);
    intent.setAction(NetworkService.ACTION_GET_CITY_INFO);
    intent.putExtra(NetworkService.EXTRA_LATLON, new LatLon(51.5073, 0.1276));
    MyReciever reciever = new MyReciever(null);
    reciever.setOnCityInfoRecieved(this);
    intent.putExtra(MyReceiver.RESULT_RECEIEVER_EXTRA, reciever);
    startService(getCityInfoIntent);
}

MyReciever class: MyReciever类:

public class MyReciever extends ResultReceiver {

    public static final String RESULT_CITY_INFO = "cityInfoData";
    public static final String RESULT_RECEIEVER_EXTRA = "reciever";

    public MyReciever(Handler handler) {
        super(handler);
    }

    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
        super.onReceiveResult(resultCode, resultData);
    }
}

IntentService: IntentService:

public class NetworkService extends IntentService {

 @Override
 protected void onHandleIntent(Intent intent) {
     if (intent != null) {
         MyReciever reciever = intent.getParcelableExtra(MyReciever.RESULT_RECEIEVER_EXTRA); //fails on this line
    }
}

What about this : 那这个呢 :

public class NetworkService extends IntentService {

 @Override
 protected void onHandleIntent(Intent intent) {
     if (intent != null) {
         ResultReceiver reciever = intent.getParcelableExtra(MyReciever.RESULT_RECEIEVER_EXTRA);
    }
}

As CREATOR has not been redefined in MyReciever, it creates ResultReceiver instances. 由于CREATOR尚未在MyReciever中重新定义,因此它会创建ResultReceiver实例。 Just receive your ResultReceiver instance from the intent as it is, a ResultReceiver. 只需从intent中接收ResultReceiver实例,即ResultReceiver。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassCastException:android.os.BinderProxy 无法转换为 com.leonard.sg.okcoin.service.SyncAndTradeService$SyncAndTradeBinder - java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.leonard.sg.okcoin.service.SyncAndTradeService$SyncAndTradeBinder java.lang.ClassCastException:com.pdf.ViewPdf无法转换为android.app.Activity - java.lang.ClassCastException: com.pdf.ViewPdf cannot be cast to android.app.Activity Android:Loop for正在获取java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMap无法强制转换 - Android: Loop for is getting java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast java.lang.ClassCastException:android.os.BinderProxy无法转换为xxx $ LocalBinder - java.lang.ClassCastException: android.os.BinderProxy cannot be cast to xxx$LocalBinder java.lang.ClassCastException: com.example.slideshowapp.MainActivity 无法转换为 android.widget.AdapterView$OnItemClickListener - java.lang.ClassCastException: com.example.slideshowapp.MainActivity cannot be cast to android.widget.AdapterView$OnItemClickListener java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap 无法转换为模型类 android - java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to model class android 原因:java.lang.ClassCastException:android.widget.RelativeLayout无法强制转换为com.slidingmenu.lib.SlidingMenu - Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to com.slidingmenu.lib.SlidingMenu java.lang.ClassCastException: com.twilio.video.VideoTextureView cannot be cast to android.widget.VideoView - java.lang.ClassCastException: com.twilio.video.VideoTextureView cannot be cast to android.widget.VideoView java.lang.ClassCastException,DeepNodeListImpl无法强制转换 - java.lang.ClassCastException, DeepNodeListImpl cannot be cast 无法将java.lang.ClassCastException强制转换为android.app.Fragment - java.lang.ClassCastException cannot be cast to android.app.Fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM