片段导航器和getActivity,getContext

时间:2019-04-22 19:29:56

标签: android fragmentnavigator

我用 fragment_navigator

创建片段

但是我想工作 processDialog ,我遇到了这个错误

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference

at androidx.navigation.fragment.FragmentNavigator$Destination.createFragment(FragmentNavigator.java:353)

代码:

...
       PerformNetworkRequest request = new PerformNetworkRequest(Api.URL_READ, null, CODE_GET_REQUEST,getContext());
        request.execute();
...

PerformNetworkRequest(String url, HashMap<String, String> params, int requestCode, Context context) {

            this.url = url;
            this.params = params;
            this.requestCode = requestCode;
            this.context = context;

        }

        @Override
        protected void onPreExecute() {

            super.onPreExecute();

                p = new ProgressDialog(context);
                p.setMessage("bla bla"); ...

0 个答案:

没有答案