PasscodeView icon indicating copy to clipboard operation
PasscodeView copied to clipboard

Null Pointer Exception

Open rmushfiqur2 opened this issue 7 years ago • 6 comments

I am getting null pointer exception on java.lang.String.length() Error: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at android.graphics.Canvas.drawText(Canvas.java:1703) at com.kevalpatel.passcodeview.internal.BoxTitleIndicator.drawView(BoxTitleIndicator.java:147) at com.kevalpatel.passcodeview.PinView.drawView(PinView.java:222) at com.kevalpatel.passcodeview.internal.BasePasscodeView.onDraw(BasePasscodeView.java:247) at android.view.View.draw(View.java:17526) at android.view.View.updateDisplayListIfDirty(View.java:16519) at android.view.View.draw(View.java:17295) at android.view.ViewGroup.drawChild(ViewGroup.java:3926) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716) at android.view.View.updateDisplayListIfDirty(View.java:16514) at android.view.View.draw(View.java:17295) at android.view.ViewGroup.drawChild(ViewGroup.java:3926) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716) at android.view.View.updateDisplayListIfDirty(View.java:16514) at android.view.View.draw(View.java:17295) at android.view.ViewGroup.drawChild(ViewGroup.java:3926) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716) at android.view.View.updateDisplayListIfDirty(View.java:16514) at android.view.View.draw(View.java:17295) at android.view.ViewGroup.drawChild(ViewGroup.java:3926) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3716) at android.view.View.draw(View.java:17529) at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:3187) at android.view.View.updateDisplayListIfDirty(View.java:16519) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:325) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:331) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:366) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3234) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3033) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2615) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1528) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7530) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:622) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) 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:7325) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

This is my xml file: ` <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="cloud.mushfiq.buet.chargesekure.pinActivity">

<com.kevalpatel.passcodeview.PinView
    android:id="@+id/pin_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:dividerColor="@color/colorPrimaryDark"
    app:fingerprintDefaultText="Scan your finger to unlock application"
    app:fingerprintEnable="true"
    app:fingerprintTextColor="@color/colorAccent"
    app:fingerprintTextSize="@dimen/finger_print_text_size"
    app:titleTextColor="@android:color/white"/>

</FrameLayout>`

This is activity.java `package cloud.mushfiq.buet.chargesekure;

import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle;

import com.kevalpatel.passcodeview.PinView; import com.kevalpatel.passcodeview.authenticator.PasscodeViewPinAuthenticator; import com.kevalpatel.passcodeview.indicators.CircleIndicator; import com.kevalpatel.passcodeview.keys.KeyNamesBuilder; import com.kevalpatel.passcodeview.keys.RoundKey;

public class pinActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pin);

    PinView pinView = (PinView) findViewById(R.id.pin_view);

    final int[] correctPin = new int[]{1, 2, 3,4};
    pinView.setPinAuthenticator(new PasscodeViewPinAuthenticator(correctPin));

    pinView.setPinLength(4);

    pinView.setKey(new RoundKey.Builder(pinView)
            .setKeyPadding(R.dimen.key_padding)
            .setKeyStrokeColorResource(R.color.colorAccent)
            .setKeyStrokeWidth(R.dimen.key_stroke_width)
            .setKeyTextColorResource(R.color.colorAccent)
            .setKeyTextSize(R.dimen.key_text_size));
    pinView.setKeyNames(new KeyNamesBuilder()
            .setKeyOne(this, R.string.key_1)
            .setKeyTwo(this, R.string.key_2)
            .setKeyThree(this, R.string.key_3)
            .setKeyFour(this, R.string.key_4)
            .setKeyFive(this, R.string.key_5)
            .setKeySix(this, R.string.key_6)
            .setKeySeven(this, R.string.key_7)
            .setKeyEight(this, R.string.key_8)
            .setKeyNine(this, R.string.key_9)
            .setKeyZero(this, R.string.key_0));

    pinView.setIndicator(new CircleIndicator.Builder(pinView)
            .setIndicatorRadius(R.dimen.indicator_radius)
            .setIndicatorFilledColorResource(R.color.colorAccent)
            .setIndicatorStrokeColorResource(R.color.colorAccent)
            .setIndicatorStrokeWidth(R.dimen.indicator_stroke_width));
}

}`

this is dim file:

20dp 3dp 25dp 25dp 15dp 5dp

What is the problem going on ?

rmushfiqur2 avatar Sep 14 '18 14:09 rmushfiqur2

Have you managed to resolve this problem? I am getting this null pointer and i am unable to fix it.

Deresh08 avatar Nov 28 '18 22:11 Deresh08

No, I didn't. I ended up with using another library.

rmushfiqur2 avatar Nov 29 '18 06:11 rmushfiqur2

No, I didn't. I ended up with using another library.

What library did you use?

Deresh08 avatar Nov 29 '18 08:11 Deresh08

https://github.com/hanks-zyh/PasscodeView

rmushfiqur2 avatar Nov 29 '18 08:11 rmushfiqur2

Any solutions yet guys?

Mustafa-Altameemi avatar Feb 15 '21 07:02 Mustafa-Altameemi

I know it is too late but for anyone who still wanna use this library (even tho it is too old) and is facing the same issue:

I had the same issue and the problem was because I forgot to set the title. I solved it by adding a title. You can add title using either of following methods. In your xml app:pin_titleText="Enter your title here" OR In your java or kotlin pinview.setTitle("Enter your title here")

HagosAlema avatar Mar 16 '22 04:03 HagosAlema