amlcurran / ShowcaseView

[Archived] Highlight the best bits of your app to users quickly, simply, and cool...ly
5.6k stars 1.29k forks source link

NullPointerException: Attempt to invoke virtual method 'void android.view.View.getLocationInWindow(int[])' on a null object reference #407

Open hasnain-ahmad opened 8 years ago

hasnain-ahmad commented 8 years ago

I want to show a ShowcaseView in ViewPager's Item's TextView. Here is my code.

@Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        View itemView = mLayoutInflater.inflate(R.layout.view_pager_item, container, false);
        TextView tvStartLockingApps = (TextView) itemView.findViewById(R.id.tv_start_locking_apps);
        final TextView tvCurrentActiveProfile = (TextView) itemView.findViewById(R.id.tv_current_active_profile);
        if (position == 1) {
            new ShowcaseView.Builder(getProfileActivity())
                    .setTarget(new ViewTarget(R.id.tv_start_locking_apps, getProfileActivity()))
                    .setStyle(R.style.CustomShowcaseTheme2)
                    .singleShot(1)
                    .setContentTitle("Just touch")
                    .setContentText("Touch to ....")
                    .hideOnTouchOutside().build();
        }
        container.addView(itemView);
        return itemView;
    }

Here is my error.

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.getLocationInWindow(int[])' on a null object reference
at com.github.amlcurran.showcaseview.targets.ViewTarget.getPoint(ViewTarget.java:41)
at com.github.amlcurran.showcaseview.ShowcaseView$1.run(ShowcaseView.java:191)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
VisheshVadhera commented 8 years ago

Did you try using View Target's other constructor which takes only the view parameter? I too was getting a NPE when I tried using the other constructor which takes in the viewId and the Activity as parameters.

JazariMusic commented 8 years ago

I am seeing many instances of the same error in production. I use the ViewTarget constructor that takes a single argument. Because of the volume of crashes, I think I will have to rip out the tutorial until it's fixed.