question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null Pointer Exception

See original GitHub issue

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: `<?xml version="1.0" encoding="utf-8"?> <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:

<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="key_padding">20dp</dimen> <dimen name="key_stroke_width">3dp</dimen> <dimen name="key_text_size">25dp</dimen> <dimen name="finger_print_text_size">25dp</dimen> <dimen name="indicator_radius">15dp</dimen> <dimen name="indicator_stroke_width">5dp</dimen> </resources>

What is the problem going on ?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

0reactions
HagosAlemacommented, Mar 16, 2022

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")

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - What is a NullPointerException, and how do I fix it?
NullPointerException s are exceptions that occur when you try to use a reference that points to no location in memory ...
Read more >
NullPointerException (Java Platform SE 7 ) - Oracle Help Center
Thrown when an application attempts to use null in a case where an object is required. These include: ... Applications should throw instances...
Read more >
Null Pointer Exception In Java - GeeksforGeeks
NullPointerException is a RuntimeException. In Java, a special null value can be assigned to an object reference. NullPointerException is thrown ...
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
The NullPointerException occurs due to a situation in application code where an uninitialized object is attempted to be accessed or modified.
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
NullPointerException is a runtime exception, so we don't need to catch it in the program. NullPointerException is raised in an application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found