mattsilber / applock

A simple library for locking and unlocking Activities with a PIN code or Fingerprint (e.g. a child lock).
Other
87 stars 43 forks source link

error while using this library #4

Closed achinverma closed 6 years ago

achinverma commented 7 years ago

Hi , i am using this library for pin lock in my app, but i am getting error , please find the below

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.guardanis.applock.pin.PINItemAnimator.cancel()' on a null object reference
11-10 15:03:46.275 30423-30423/competent.groove.feetport W/System.err:     at com.guardanis.applock.pin.PINInputView.cancelPreviousAnimation(PINInputView.java:183)
11-10 15:03:46.275 30423-30423/competent.groove.feetport W/System.err:     at com.guardanis.applock.pin.PINInputView.animate(PINInputView.java:173)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at com.guardanis.applock.pin.PINInputView.animateLastIn(PINInputView.java:169)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at com.guardanis.applock.pin.PINInputView.afterTextChanged(PINInputView.java:154)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.widget.TextView.sendAfterTextChanged(TextView.java:7706)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:9494)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:972)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:516)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:454)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:33)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:121)
11-10 15:03:46.276 30423-30423/competent.groove.feetport W/System.err:     at android.widget.TextView.doKeyDown(TextView.java:5812)
11-10 15:03:46.277 30423-30423/competent.groove.feetport W/System.err:     at android.widget.TextView.onKeyDown(TextView.java:5625)
11-10 15:03:46.277 30423-30423/competent.groove.feetport W/System.err:     at android.view.KeyEvent.dispatch(KeyEvent.java:2632)
11-10 15:03:46.277 30423-30423/competent.groove.feetport W/System.err:     at android.view.View.dispatchKeyEvent(View.java:8416)
11-10 15:03:46.278 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.278 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1495)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2361)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1709)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.app.Activity.dispatchKeyEvent(Activity.java:2712)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:543)
11-10 15:03:46.279 30423-30423/competent.groove.feetport W/System.err:     at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:53)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:315)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:53)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2276)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4090)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4052)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3657)
11-10 15:03:46.280 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3623)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3740)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3631)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3797)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3657)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3623)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3631)
11-10 15:03:46.283 30423-30423/competent.groove.feetport W/System.err:     at 
achinverma commented 7 years ago

i will post my code in my activity

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/pattern_view_status"
        android:layout_margin="20dp"
        android:orientation="vertical">

        <com.guardanis.applock.pin.PINInputView
            android:id="@+id/pin__input_view"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/pin__default_item_size" />

    </LinearLayout>

public class PinLockActivity extends AppCompatActivity {

    private Toolbar mToolbarView;
    PINInputView pinInputView;
    protected PINInputController inputController;
    private int inputViewsCount = 4;
    private ActivityLockingHelper lockingHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pin_lock);
        Slidr.attach(this);

        lockingHelper = new ActivityLockingHelper(this, null);

        pinInputView  = (PINInputView) findViewById(R.id.pin__input_view);
        mToolbarView = (Toolbar) findViewById(R.id.choosePintoolbar);
        mToolbarView.setTitle("");
        setSupportActionBar(mToolbarView);

        assert getSupportActionBar() != null;
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        inputController = new PINInputController(pinInputView, null);
        inputController.setInputEventListener(new PINInputController.InputEventListener() {
            @Override
            public void onInputEntered(String input) {
                Log.e("setInputEventListener",""+input);
                if(input.length() < inputViewsCount) {

                }else{

                }
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(final MenuItem menu) {
        switch (menu.getItemId()) {
            case android.R.id.home:
                this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(menu);
        }
    }
}
mattsilber commented 7 years ago

I don't see anything that would cause it to crash. The line your Exception is referencing is wrapped in a try/catch that prints the error (which would only ever be the NullPointerException you're seeing, which is should be generally safe to ignore if it happens).

Are you experiencing a crash, is it not working correctly, or is this just in your logs and you're concerned?

If it's one of the former two, then try explicitly calling setInputNumbersCount(inputViewsCount) on your inputController before adding the event listener. It looks like without the Intent overrides from the base classes I built, the default input count may not line up with yours.

achinverma commented 7 years ago

@mattsilber i am not getting any crash but when user enter the pin i am not able get output in

inputController.setInputEventListener(new PINInputController.InputEventListener() {
            @Override
            public void onInputEntered(String input) {
                Log.e("setInputEventListener",""+input);
            }
        });

i mean my this line is not printing any value when user enters the pin in PINInputView Log.e("setInputEventListener",""+input);

mattsilber commented 7 years ago

The callback is being triggered, but the data isn't being passed back? And you've tested this with full input entered?

Can you also check if the base helper classes are working for you, to see if this is an issue with the library, or an issue with the implementation:

new CreateLockDialogBuilder(Activity, 
    new LockCreationListener(){
        public void onLockCanceled(){ } // Dialog was closed without entry
        public void onLockSuccessful(){
            ActionLockingHelper.unlockIfRequired(Activity, new UnlockEventListener(){
                public void onCanceled(){ } // Dialog was closed without entry
                public void onUnlockFailed(String reason){ } // Not called with default Dialog, instead is handled internally
                public void onUnlockSuccessful(){
                    Log.d("AppLock", "Unlock successful");
                 }
             });
        }
    })
    .show();

If you just run that blob within your app, that should open the create dialog, and, on success, open the unlock dialog. If unlocking is successful, then there may be something weird going on with your setup, but this should point us in the right direction.

mattsilber commented 6 years ago

Closed since it's almost been 2 years and I'm about to push a large update...