I am adding and removing view dynammically, as follows:
Codes:
view_share_dialog = findViewById(R.id.view_share_coloring);
case R.id.btn_share_coloring:
if(btn.isChecked())
{
CloseOpenedView(btn);
AnimUtils.slideToLeft_ColorView(view_share_dialog, mContext);
view_share_dialog.bringToFront();
mDrawView.newLine(android.R.color.transparent);
Toast.makeText(getApplicationContext(), "FRONT", Toast.LENGTH_SHORT).show();
}
else
{
img.bringToFront();
AnimUtils.slideToRight_ColorView(view_share_dialog, mContext);
mDrawView.newLine(Color.parseColor(allColors[lastSelectedCol]));
((RelativeLayout)view_share_dialog.getParent()).removeView(view_share_dialog);
Toast.makeText(getApplicationContext(), "GONE", Toast.LENGTH_SHORT).show();
}
break;
// these are the buttons of choices for sharing in the View
public void shareButtonClickable(boolean clickable)
{
findViewById(R.id.btn_share_copy).setClickable(clickable); //line 467
findViewById(R.id.btn_share_email).setClickable(clickable);
findViewById(R.id.btn_share_facebook_c).setClickable(clickable);
findViewById(R.id.btn_share_photo_album).setClickable(clickable);
}
Logcat:
06-22 01:52:36.571: E/AndroidRuntime(15096): Caused by: java.lang.reflect.InvocationTargetException
06-22 01:52:36.571: E/AndroidRuntime(15096): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 01:52:36.571: E/AndroidRuntime(15096): at java.lang.reflect.Method.invoke(Method.java:515)
06-22 01:52:36.571: E/AndroidRuntime(15096): at android.view.View$1.onClick(View.java:3964)
06-22 01:52:36.571: E/AndroidRuntime(15096): ... 12 more
06-22 01:52:36.571: E/AndroidRuntime(15096): Caused by: java.lang.NullPointerException
06-22 01:52:36.571: E/AndroidRuntime(15096): at com.abc.abc.ColoringPageActivity.shareButtonClickable(ColoringPageActivity.java:467)
06-22 01:52:36.571: E/AndroidRuntime(15096): at com.abc.abc.ColoringPageActivity.onClickToggle_coloring(ColoringPageActivity.java:528)
06-22 01:52:36.571: E/AndroidRuntime(15096): ... 15 more
Question:
For the first time pressing the btn_share_coloring
button, the view can be animated from right of screen to the center. And then when the btn_share_coloring
is pressed again (i.e. unchecked), the view can also be animated from center to the right, with the Toast
"Gone" can be properly shown. Yet when the user further press again for the btn, a fatal NPE will be resulted.
While the View can be properly being removed, how could the view be inflated again properly?
Thanks!