TapTargetView
TapTargetView copied to clipboard
java.lang.IllegalArgumentException: Given null view to target
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);
}
}
You have to inflate the menu to mToolbar.
@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
:)
This solved the issue for me thanks