最近在学习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. HTML5之字体

    - 使用CSS样式来定义 context.font = [CSS font property] context.font = [font-style font-variant font-weight ...

  2. php configure help

    `configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION].. ...

  3. jQuery Mobile里xxx怎么用呀? (事件篇)

    jQuery Mobile里$(document).ready()怎么用呀? 相关链接: http://stackoverflow.com/questions/14468659/jquery-mobi ...

  4. 对WebClient扩展自动解压缩页面

    WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...

  5. SSH调试

    <s:date>标签中若是用date数组或Calendar数组,则永远显示数组最后一个数. 试试List.Set.Map也不行. 看来只能够使用单个对象.或者在后台传送String 数组, ...

  6. gentoo下grub文件编辑

    在编译完内核,配置好网络,配置好fstab文件等等,最后一个至关重要的文件要属grub文件了,该文件的配置成功才最终决定gentoo 是否成功装上,首先当然是 emerge grub 了,现在就可以配 ...

  7. B树及2-3树的python实现

    B树(或称B-树)是一种适用于外查找的树,它是一种平衡的多叉树. 阶为M的B树具有下列结构特征: 1.树的根或者是一片树叶,或者其儿子数在2和M之间. 2.除根节点外的所有非树叶节点儿子数在┌M/2┐ ...

  8. 常用 xwt 工具

    1,显示提示信息 <FString chnName="执行单位" prompt="可以进行模糊匹配" required="false" ...

  9. 【IT历史】SP和CP

    1.什么是SP?SP是英文Service Provider的缩写,中文翻译为服务提供商,通常是指在移动网内运营增值业务的社会合作单位.它们建立与移动网络建立相连的服务平台,为手机用户提供一系列信息服务 ...

  10. 史上最全github使用方法:github入门到精通--备用

    [初识Github] 首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理 ...