TapTargetView icon indicating copy to clipboard operation
TapTargetView copied to clipboard

java.lang.IllegalArgumentException: Given null view to target

Open tranquoctrungcntt opened this issue 5 years ago • 3 comments

this exception happens even when I write a condition if ( view !=null ) for it.

this is my code

    setSupportActionBar(mToolbar);
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu,menu);
        return super.onCreateOptionsMenu(menu);

    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
          ShowCaseFirstRun();
        return super.onPrepareOptionsMenu(menu);

    }
private void ShowCaseFirstRun() {

        boolean check = SharePreferencesUtils.getFirstOpenAppFromSharePref(this);

        if (check){

            MenuItem menuItem=mToolbar.getMenu().findItem(R.id.item_search);
            MenuItem menuItem2=mToolbar.getMenu().findItem(R.id.item_new);
            if (menuItem!=null && menuItem2!=null && mToolbar!=null){

                new TapTargetSequence(this).targets(TapTarget.forToolbarMenuItem(mToolbar,menuItem.getItemId(),
                        ".")
                                .outerCircleColor(R.color.colorAccent)
                                .targetCircleColor(R.color.white)
                                .outerCircleAlpha(0.96f)
                                .titleTextSize(20)
                                .tintTarget(true)
                                .descriptionTextSize(15)
                                .textColor(R.color.white)
                                .textTypeface(Typeface.SANS_SERIF)
                                .cancelable(false)
                                .targetRadius(60)).start();

            }




            SharePreferencesUtils.UpdateFirstOpenAppToSharePref(this);

        }
    }

tranquoctrungcntt avatar Apr 10 '19 03:04 tranquoctrungcntt

You have to inflate the menu to mToolbar.

PrimozPernat avatar Oct 11 '19 21:10 PrimozPernat

@tranquoctrungcntt
you have to explicitly inflate the menu to mToolbar like private Toolbar mToolbar = findViewById(R.id.mainToolbar); mToolbar.inflateMenu(R.menu.main_menu) ; otherwise it will always through NULLPOINTER EXCEPTION :)

ranaaditya avatar Jan 17 '20 14:01 ranaaditya

This solved the issue for me thanks

netvor-73 avatar Jul 26 '21 14:07 netvor-73