0

After going through:

Unable to add window -- token null is not valid; is your activity running?

Android 'Unable to add window -- token null is not for an application' exception

Dialog throwing "Unable to add window — token null is not for an application” with getApplication() as context

BadTokenException: Unable to add window -- token null is not valid; is your activity running? in activity.isFinishing statment

Problems creating a Popup Window in Android Activity

It returns null when I use getView() to get root View of the Fragment in the ViewPager

I'm not entirely sure if having a null View element as root causes this exception. I have a DialogFragment:

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.acquire_fragment, container, false);

    mErrorTextView = root.findViewById(R.id.error_textview);
    mRecyclerView = root.findViewById(R.id.list);
    mLoadingView = root.findViewById(R.id.screen_wait);

    Toolbar toolbar = root.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
            mListener.onFinishActivity();
        }
    });
    toolbar.setTitle(R.string.button_purchase);
    return root;
}

Can root be null when .findViewById() is called?

Sebi
  • 4,262
  • 13
  • 60
  • 116
  • I think it's the `container` that is null, could it be that the activity associated with this dialog was at the time this dialog was being created? – Zohaib Amir Oct 31 '19 at 22:29
  • @ZohaibAmir It happens on some devices; is it possible to postpone onCreate() until all parameters are initialized? – Sebi Oct 31 '19 at 22:44

0 Answers0