Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为通用util制作Android库_Java_Android_Deployment_Guava - Fatal编程技术网

Java 为通用util制作Android库

Java 为通用util制作Android库,java,android,deployment,guava,Java,Android,Deployment,Guava,我正在制作Android库,供我的项目使用,该项目需要一些通用工具 以及 在我的项目(使用Android Studio)中,我将Lint检查,@NotNull/@Nullable problems设置为错误严重性 在我的公共工具库中,有一个类DebugPremissions,它涉及大量的条件检查。作为 DebugPreconditions.checkNotNull(fragment); Bundle bundle = fragment.getArguments(); bundle.putStri

我正在制作Android库,供我的项目使用,该项目需要一些通用工具

以及

  • 在我的项目(使用Android Studio)中,我将Lint检查,
    @NotNull/@Nullable problems
    设置为错误严重性

  • 在我的公共工具库中,有一个类DebugPremissions,它涉及大量的条件检查。作为

    DebugPreconditions.checkNotNull(fragment);
    Bundle bundle = fragment.getArguments();
    bundle.putString(MainActivity.ARGS_SHOP_ID, shopId);
    activity.replaceFragment(fragment, R.id.fragment_container, true);
    
  • DebugPremissions.checkNotNull

    /**
     * Ensures that an object reference passed as a parameter to the calling method is not null.
     * @param <T>       the type parameter
     * @param reference an object reference
     * @return the non-null reference that was validated
     * @throws NullPointerException if {@code reference} is null
    */
    public static <T> T checkNotNull(@Nullable T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }
    
    /**
    *确保作为参数传递给调用方法的对象引用不为null。
    *@param类型参数
    *@param引用对象引用
    *@返回已验证的非空引用
    *如果{@code reference}为空,@将引发NullPointerException
    */
    公共静态T checkNotNull(@Nullable T reference){
    if(reference==null){
    抛出新的NullPointerException();
    }
    返回参考;
    }
    
    我遇到的问题是,, Android检查仍发现存在问题,可能导致'fragment.getArguments()上出现'NullPointerException'

    但是,如果我使用谷歌番石榴的错误通知将消失

    有人能帮我吗

    试试这个:

    /**
     * Ensures that an object reference passed as a parameter to the calling method is not null.
     * @param <T>       the type parameter
     * @param reference an object reference
     * @return the non-null reference that was validated
     * @throws NullPointerException if {@code reference} is null
    */
    @NotNull // <-- This is important.
    public static <T> T checkNotNull(@Nullable T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }
    

    如果
    fragment
    被声明为
    final
    ,则它不起作用。以及如何实现像谷歌番石榴那样的先决条件。checkNotNull?我不明白它有什么区别,我的和它是一样的…@lekaha试着从参数
    t reference
    中删除
    @Nullable
    注释,所以现在错误移动到检查的行上,
    debugpremissions.checkNotNull(片段)我认为我的代码与Java编译器的代码几乎相同,除非Java编译器在后面执行,否则这可能是我想知道的。
    
    fragment = DebugPreconditions.checkNotNull(fragment);