小编Tea*_*sel的帖子

:当 getView() 为 null 时,即在 onCreateView() 之前或 onDestroyView() 之后,无法访问片段视图的 LifecycleOwner

我在我的应用程序中使用实时数据进行所有网络调用和响应处理。

在其中一种情况下,我的回收器视图正在其视图持有者的视图中加载一些数据,onBind并且响应正在更新 UI。为此,我必须向lifecycleOwner观察者提供一个。

由于回收器视图没有自己的任何生命周期所有者,因此我正在使用父片段,parentFragment.viewlifecycleOwner但不知何故它给出了错误。

当父片段没有实例时,视图持有者如何拥有其实例?

viewModel.responseState.observe(parentFragment.viewLifecycleOwner, Observer {
    updateUI(it)
})
Run Code Online (Sandbox Code Playgroud)

致命异常:java.lang.IllegalStateException:当 getView() 为 null 时,即在 onCreateView() 之前或 onDestroyView() 之后,无法访问 Fragment View 的 LifecycleOwner

android android-lifecycle android-recyclerview

21
推荐指数
3
解决办法
1万
查看次数

通过改造在POST请求中发送JSON

我已经多次看到这个问题并尝试了很多解决方案但是没有解决我的问题,我正在尝试使用改造在POST请求中发送json,我不是编程专家所以我可能会错过一些明显的东西.

我的JSON是一个字符串,看起来像这样:

{"id":1,"nom":"Hydrogène","slug":"hydrogene"}
Run Code Online (Sandbox Code Playgroud)

我的界面(称为APIService.java)看起来像这样:

@POST("{TableName}/{ID}/update/0.0")
Call<String> cl_updateData(@Path("TableName") String TableName, @Path("ID") String ID);
Run Code Online (Sandbox Code Playgroud)

我的ClientServiceGenerator.java看起来像这样:

public class ClientServiceGenerator{
private static OkHttpClient httpClient = new OkHttpClient();

public static <S> S createService(Class<S> serviceClass, String URL) {
    Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(URL)
                    .addConverterFactory(GsonConverterFactory.create());

    Retrofit retrofit = builder.client(httpClient).build();
    return retrofit.create(serviceClass);
}}
Run Code Online (Sandbox Code Playgroud)

最后这是我活动中的代码

APIService client = ClientServiceGenerator.createService(APIService.class, "http://mysiteexample.com/api.php/");
    Call<String> call = client.cl_updateData("atomes", "1");
    call.enqueue(new Callback<String>() {
        @Override
        public void onResponse(Response<String> response, Retrofit retrofit) {
            if (response.code() == 200 && response.body() != null){ …
Run Code Online (Sandbox Code Playgroud)

java post android json retrofit

13
推荐指数
1
解决办法
2万
查看次数

ngAfterViewInit 的单元测试?

我是为 angular 编写单元测试用例的新手。我必须为ngAfterViewInit编写一个测试用例。我不知道如何开始。我正在使用角度 7。

我的组件代码:

export class MyAccessComponent implements OnInit, AfterViewInit {

    // Spinner
    pageLoaded: boolean;
    @Input() diameter = 64;
    @Input() strokeWidth = 7;

    // Icons
    faEdit = faEdit;

    dataSource;
    @ViewChild(MatPaginator) paginator: MatPaginator;

    constructor(private router: Router, private userService: UserService) { }

    ngOnInit() {
        this.pageLoaded = false;
        // Data table init
        this.getUsers();
    }

    ngAfterViewInit() {
        setTimeout(() => {
            this.pageLoaded = true;
        }, 500);
    }
}
Run Code Online (Sandbox Code Playgroud)

unit-testing angular

6
推荐指数
1
解决办法
8414
查看次数

非现有变量的默认值

我正在开发一个基于VBA excel的项目,并在调用变量时输入错误.在尝试调试函数一段时间后,我意识到我正在引用一个不存在的变量(因为错字)但调试器没有指出问题.

我试图获取变量的值,结果为空.我试图与变量进行比较,每次都返回false.

我想知道,如果它有什么做的Boolean是默认值False(作为VB语言说,微软在这里)?如果是这样的话,为什么打印没有价值呢?

另外,为什么调试器没有问题?

Sub MySub()
    'Print absolutely nothing
    Debug.Print myVariable

    If (myVariable) Then
        Debug.Print "Condition is true"
    Else
        'The condition always comes in that
        Debug.Print "Condition is false"
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

vba

1
推荐指数
1
解决办法
59
查看次数