دنبال کننده ها

۱۳۹۶ اسفند ۹, چهارشنبه

Attempt to write to field 'android.view.ViewParent android.view.View.mParent' on a null object reference

[ad_1]



I have an activity (say A )which is launched in singleTask mode. I created a view in this activity which looks like popup and added it to the parent view of the activity A. Now i launched Activity A from somewhere else , since its singleTask so i receive onNewIntent() call, where i reinitialise the new view. But how do i destroy this popup before i reinitialise A.



Here is my code :
This is how i created popup.



 final ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView();
RelativeLayout popup = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.popup_r,null);
popupView = popup;
rootView.addView(popup);


Here is my onNewIntent method



@Override
protected void onNewIntent(Intent intent)
super.onNewIntent(intent);

if (popupView != null)

((ViewGroup)popupView.getParent()).removeView(popupView);
popupView = null;


setIntent(intent);
setContentView(R.layout.activity_view);
reinitView();



But This give me crash saying :



java.lang.NullPointerException: Attempt to write to field 'android.view.ViewParent android.view.View.mParent' on a null object reference



at line ((ViewGroup)popupView.getParent()).removeView(popupView);



How do remove popupview before reinitialising activity with new intent.




[ad_2]

لینک منبع