我一直在尝试在我的项目中实现passcodeView
库,以便于登录而不是默认登录功能。我已按照所有步骤进行操作,但仍收到无法解决的错误。请我提供解决方案。
该数组不断返回null并崩溃了我的应用程序,但它不是null。
public class QuickLoginActivity extends AppCompatActivity {
private static final String ARG_CURRENT_PIN = "current_pin";
private PinView mPinView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quick_login);
//Set the correct pin code.
//REQUIRED
mPinView = findViewById(R.id.pattern_view);
final int[] correctPattern = new int[]{1, 2, 3, 4};
mPinView.setPinAuthenticator(new PasscodeViewPinAuthenticator(correctPattern));
//Build the desired key shape and pass the theme parameters.
//REQUIRED
mPinView.setKey(new RoundKey.Builder(mPinView)
.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));
//Build the desired indicator shape and pass the theme attributes.
//REQUIRED
mPinView.setIndicator(new CircleIndicator.Builder(mPinView)
.setIndicatorRadius(R.dimen.indicator_radius)
.setIndicatorFilledColorResource(R.color.colorAccent)
.setIndicatorStrokeColorResource(R.color.colorAccent)
.setIndicatorStrokeWidth(R.dimen.indicator_stroke_width));
mPinView.setPinLength(4);
mPinView.setTitle("Enter the PIN");
mPinView.setAuthenticationListener(new AuthenticationListener() {
@Override
public void onAuthenticationSuccessful() {
//User authenticated successfully.
//Navigate to secure screens.
startActivity(new Intent(QuickLoginActivity.this, MainActivity.class));
finish();
}
@Override
public void onAuthenticationFailed() {
//Calls whenever authentication is failed or user is unauthorized.
//Do something
}
});
}
private void sendToLogin() {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putIntArray(ARG_CURRENT_PIN, mPinView.getCurrentTypedPin());
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mPinView.setCurrentTypedPin(savedInstanceState.getIntArray(ARG_CURRENT_PIN));
}
}
StackTrace
E/UncaughtException: java.lang.NullPointerException: Attempt to read from null array
at com.kevalpatel.passcodeview.internal.BoxKeypad.measureView(BoxKeypad.java:181)
at com.kevalpatel.passcodeview.PinView.measureView(PinView.java:182)
at com.kevalpatel.passcodeview.internal.BasePasscodeView.onMeasure(BasePasscodeView.java:212)
at android.view.View.measure(View.java:20665)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:825)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:511)
at android.view.View.measure(View.java:20665)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6320)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:214)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLay
答案 0 :(得分:1)
发生这种情况是因为您没有设置键名。您应该添加:
mPinView.setKeyNames(new KeyNamesBuilder());