最近在学习RxJava 感觉很happy ,happy的同时遇到不少问题 没办法一点一点来 上张帅图先

在使用RxJava + Retrofit 的时候 有时候接口请求参数不规范

比如 {}

@FormUrlEncoded
@POST("get_info")
Observable<String> getInfo(@Field("{}") String json); 但是怎么既能够返回
new BaseSubscribe<String>()
有能够返回
new BaseSubscribe<实体类呢?>()

查到
ScalarsConverterFactory scalarsConverterFactory = ScalarsConverterFactory.create();
.addConverterFactory(scalarsConverterFactory)来增加字符串请求

使用
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create();
.addConverterFactory(gsonConverterFactory)增加实体类请求

但是 我这样做了却不行
后来查到 要这样才行==
可能是版本问题吧。。
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(new Gson());

ScalarsConverterFactory scalarsConverterFactory = ScalarsConverterFactory.create();

.baseUrl(ConstantApi.baseUrl)
.addConverterFactory(scalarsConverterFactory)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build(); 别忘了:
//RxJava与Retrofit的适配器
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-scalars:2.1.0' 参考 :http://www.th7.cn/Program/Android/201605/851109.shtml
http://www.jianshu.com/p/dbc46cc033fb
感谢作者 最后截个图看一下目前的代码结构 很酸爽有木有。。。

另外关于新手使用RxJava需要注意的:

subscriptions = new CompositeSubscription();

        service = GithubService.createGithubService(githubToken);
        view.setOnClickListener( v -> {
            Subscription sub = service.user(name)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(System.out::println);
            subscriptions.add(sub);
        });

new CompositeSubscription();来添加 每次请求返回的Subscription对象 记得在BaseActivity中subscription.unsubscribe();

参考:http://blog.chengyunfeng.com/?p=1010感谢 原作者原文中还有很多值得研究学习的东西

java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.的更多相关文章

  1. Exception thrown on Scheduler.Worker thread. Add `onError` handling

    <html> <head></head> <body> java.lang.IllegalStateException: Exception throw ...

  2. 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called

    错误: 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutput ...

  3. 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response

    严重: Servlet.service() for servlet jsp threw exception    java.lang.IllegalStateException: getOutputS ...

  4. nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  5. nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' a

    公司还用的是spring低版本,今天用jre 8测试了一下,发现错误: Unexpected exception parsing XML document from class path resour ...

  6. Exception in thread "main" java.lang.IllegalStateException: Failed to read 问题解决

    开发中偶尔遇到这样的问题:Exception in thread "main" java.lang.IllegalStateException: Failed to read .. ...

  7. Springboot 上传报错: Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceede

    Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The ...

  8. 异常-User class threw exception: java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext.

    1 详细信息 User class threw exception: java.lang.IllegalStateException: Cannot call methods on a stopped ...

  9. SpringBoot整合Elasticsearch启动报错处理 nested exception is java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]

    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean wit ...

随机推荐

  1. PHOTOSHOP 制作虚线和实线

    1.制作实线可以直接用直线工具,选择合适的粗细大小. 2. 制作虚线首先要用钢笔或者绘图工具画出所需要的形状,如弧线,圆形等等     然后在路径面板中用画笔描边,画笔需要提前设置好粗细和间距,用方形 ...

  2. preg_match_all, preg_match

    int preg_match(string $pattern, string $subject[, $arr][, int $flags]);$pattern 正则表达式$subject: 要搜索的字 ...

  3. API获得ip,JS获得IP地理信息

      <script type="text/javascript" src="http://zone.xmp.kankan.xunlei.com/find_area_ ...

  4. winform水晶报表编译错误,未能加载文件或程序集"file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framewor "

    未能加载文件或程序集“file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Commo ...

  5. json 筛选数据 $.grep过滤数据

    var data = { status: "ok", image_size_list: [ { image_size_id: "22", ad_class: & ...

  6. select框默认样式去除(ie中隐藏默认下拉图标)

    html代码 <select class="info-select"> <option selected="selected">1< ...

  7. linux下python导出sybase 数据库 表记录的方式

    导出sybase 数据库 表记录的方式 1 执行启动sybase 数据库命令 code : dbeng7 gkdb 2 执行 连接sybase 数据库命令code : dbisql -c " ...

  8. GAC write failed when upgrade with InstallShield

    在接近final-build的时候,突然发现当前版本从上一个版本upgrade的时候,需要写到GAC (Global Assembly Cache)的assambly会写失败掉.但是只会在特定的Mic ...

  9. Oracle分析函数之FIRST_VALUE和LAST_VALUE

    FIRST_VALUE 返回组中数据窗口的第一个值 FIRST_VALUE ( [scalar_expression )OVER ( [ partition_by_clause ] order_by_ ...

  10. ionic+angulajs

    基于ionic+angulajs的混合开发实现地铁APP 项目源码地址:https://github.com/zhangxy1035/SubwayMap 一.项目简介 在该项目中的地铁app是基于io ...