简体   繁体   English

为什么“订阅” function 没有注册? RxJava Android Studio

[英]Why is 'subscribe' function not registering? RxJava Android Studio

I'm writing code for a splash screen as part of a project but when I am trying to use RxJava all the other functions are working fine until I get to 'subscribe' which isn't registering so I'm wondering am I missing a library I didn't import or something?我正在为启动屏幕编写代码作为项目的一部分,但是当我尝试使用 RxJava 时,所有其他功能都可以正常工作,直到我得到未注册的“订阅”,所以我想知道我是否错过了我没有导入的库还是什么?

The error message I get when trying to run is: 'Cannot resolve method 'subscribe'.我在尝试运行时收到的错误消息是:'无法解析方法'订阅'。 I've tried asking the tutorial creator, as well as looking at the top relevant questions about the 'subscribe' function on StackOverflow and even looking at the full list of methods in the Completable library but I can't find a solution so I'm really desperate, please help我试过询问教程创建者,以及查看有关 StackOverflow 上“订阅”function 的最重要的相关问题,甚至查看 Completable 库中的完整方法列表,但我找不到解决方案,所以我我真的很绝望,请帮助

These are my dependencies:这些是我的依赖项:

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.20'

My Code:我的代码:

package codebymech.fyprideshareapp;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.os.Bundle;
import android.widget.Toast;

import java.util.concurrent.TimeUnit;

import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Action;


public class Activity_SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        delay_Splash();
    }

        private void delay_Splash() {
            Completable.timer(delay: 5, TimeUnit.SECONDS,
                AndroidSchedulers.mainThread())
                .subscribe(new Action() {
                    @Override
                    public void run() throws Exception {
                        Toast.makeText(Activity_SplashScreen.this, "!! Splash Screen Finished", Toast.LENGTH_SHORT).show();
                    }

                });
    }
}

Part of tutorial where the code is from: https://youtu.be/144TuYxEu2M?t=489部分教程代码来自: https://youtu.be/144TuYxEu2M?t=489

You have to remove delay: .你必须删除delay: This is not possible in Java.这在 Java 中是不可能的。 If you look at the video, you see a delay: in given method, but it is added by the IDE (IntelliJ) in order to give you a hint, which parameter you are currently editing.如果你看视频,你会看到一个delay:在给定的方法中,但它是由 IDE (IntelliJ) 添加的,以便给你一个提示,你当前正在编辑哪个参数。

Import进口

import io.reactivex.Completable;
import io.reactivex.functions.Action;
import io.reactivex.schedulers.Schedulers;

Java8 Java8

   Completable.timer(5, TimeUnit.SECONDS,
            Schedulers.trampoline())
            .subscribe(() -> {
               System.out.println("x");
            });

Java7 Java7

    Completable.timer(5, TimeUnit.SECONDS,
            Schedulers.trampoline())
            .subscribe(new Action() {
                @Override
                public void run() throws Exception {
                    System.out.println("x");
                }
            });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM