regulaforensics / DocumentReader-Android

Android Framework for reading and validation of identification documents
64 stars 26 forks source link

java.lang.NullPointerException #31

Closed Reflector93 closed 3 years ago

Reflector93 commented 3 years ago

Hi, when i implemented not a full library users getting NullPointerException

java.lang.NullPointerException: at com.regula.documentreader.api.UniversalDataTransceiver$1.run (UniversalDataTransceiver.java:72) at java.lang.Thread.run (Thread.java:919)

//Regula implementation('com.regula.documentreader:api:+@aar') {transitive = true} implementation 'com.regula.documentreader.core:ocrandmrz:+@aar'

Code, which start the doc scanner and recognition

try
        {
            InputStream licInput = getResources().openRawResource(R.raw.regula);
            int available = licInput.available();
            byte[] license = new byte[available];
            licInput.read(license);

            DocumentReader.Instance().functionality().edit().setShowCaptureButton(true).apply();
            DocumentReader.Instance().functionality().edit().setShowCaptureButtonDelayFromStart(0).apply();
            DocumentReader.Instance().processParams().doublePageSpread = true;
            DocumentReader.Instance().initializeReader(activity, license, (success, error) ->
            {
                if(success)
                {
                    DocumentReader.Instance().processParams().scenario = "Ocr";
                    fabMenu.setOnClickListener( v -> scanDocument() );
                    fabMenu.setVisibility(View.VISIBLE);
                }
                else
                {
                    activity.workError.showError(error, WorkError.TOASTY_LONG, null);
                }
            });
        }
        catch(Exception ex)
        {
            activity.workError.showError(ex, WorkError.TOASTY_LONG, null);
        }

Is there any way to fix it without adding the full library? Thx a lot.

vyakimchik commented 3 years ago

Hello,

This should not be dependent on the Core mode. The issue is in the API library according to the provided error. Could you please describe the steps on how to reproduce the issue?

Reflector93 commented 3 years ago

Unfortunately, i'd got the full way of catching this error. But we inititate this code in the moment, when fragment start. The "hole" workaround is below `private void drawEdocflow(OutfitEdocflow edocflow) { dataView.removeAllViews();

    if( edocflow.getTask() != null )
    {
        new NameValue
        (
            activity,
            dataView,
            getString(R.string.otfdet_edoc_status),
            edocflow.getTask().getStatusName(),
            null
        );

        new NameValue
        (
            activity,
            dataView,
            getString(R.string.otfdet_edoc_phone),
            edocflow.getTask().getPhone(),
            null
        );

        if( edocflow.getTask().getShowReason() )
            new NameValue
            (
                activity,
                dataView,
                getString(R.string.otfdet_edoc_reason),
                edocflow.getTask().getReasonName(),
                null
            );

        new NameValue
        (
            activity,
            dataView,
            getString(R.string.otfdet_edoc_installation_code),
            installerCode,
            () ->
            {
                ClipboardManager clipboard = (ClipboardManager) activity.getSystemService( Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("code", installerCode);

                if( clipboard != null )
                {
                    clipboard.setPrimaryClip( clip );
                    Toasty.info
                    (
                        activity,
                        getResources().getString(R.string.edocflow_copy_code_success),
                        Toast.LENGTH_SHORT,
                        true
                    ).show();
                }
            }
        );
    }

    if( edocflow.getCanFillEcontact() )
    {
        layoutWork = new LayoutWork();
        new Header( activity, dataView, getString(R.string.otfdet_edoc_document) )
                .setPadding(5, 5);
        RadioGroup documentType = new RadioGroup
        (
            activity,
            dataView,
            null,
            "",
            LinearLayout.HORIZONTAL,
            new FieldInterface()
            {
                @Override
                public void OnChoose(Field.Value data)
                {
                    savedType = data.getValue();
                    selectDocument( data.getValue() );
                }

                @Override
                public void OnClear() {}
            }
        );
        documentType.addButton(getString(R.string.otfdet_edoc_document_passport), PASSPORT);
        documentType.addButton(getString(R.string.otfdet_edoc_document_others), "OTHERS");
        drawFields();

        new Space(activity, dataView, null, 5, 5);
        StringButton saveButton = new StringButton
        (
            activity,
            dataView,
            null,
            getString(R.string.otfdet_edoc_save),
            this::save
        );
        saveButton.setGravity(Gravity.CENTER_HORIZONTAL);
        saveButton.seTextSize(19);

        new Space(activity, dataView, null, 0, 5);
        StringButton cancelButton = new StringButton
        (
            activity,
            dataView,
            null,
            getString(R.string.otfdet_edoc_cancel),
            this::cancel
        );
        cancelButton.setGravity(Gravity.CENTER_HORIZONTAL);
        cancelButton.seTextSize(19);
        cancelButton.setTextColor( ContextCompat.getColor(activity, R.color.colorErrorText) );

        if( savedType != null )
        {
            documentType.setValue(savedType);
            selectDocument(savedType);
        }
        else
        {
            initScanner(true);
            selectDocument(PASSPORT);
        }
    }
    else
    {
        initScanner(false);
    }
}`

`private void initScanner(boolean showScanner) { if(!showScanner) { fabMenu.setOnClickListener(null); fabMenu.setVisibility(View.GONE); return; }

    try
    {
        InputStream licInput = getResources().openRawResource(R.raw.regula);
        int available = licInput.available();
        byte[] license = new byte[available];
        licInput.read(license);

        DocumentReader.Instance().functionality().edit().setShowCaptureButton(true).apply();
        DocumentReader.Instance().functionality().edit().setShowCaptureButtonDelayFromStart(0).apply();
        DocumentReader.Instance().processParams().doublePageSpread = true;
        DocumentReader.Instance().initializeReader(activity, license, (success, error) ->
        {
            if(success)
            {
                DocumentReader.Instance().processParams().scenario = "Ocr";
                fabMenu.setOnClickListener( v -> scanDocument() );
                fabMenu.setVisibility(View.VISIBLE);
            }
            else
            {
                activity.workError.showError(error, WorkError.TOASTY_LONG, null);
            }
        });
    }
    catch(Exception ex)
    {
        activity.workError.showError(ex, WorkError.TOASTY_LONG, null);
    }
}`

Hope, this will help to recognise the potential problem. Thx a lot:)

vyakimchik commented 3 years ago

@Reflector93, could you please send us a small demo project where this issue can be reproduced? Please send it at support@regulaforensics.com.

Reflector93 commented 3 years ago

Unfortunately, couldn't send any samples or hole code parts cause of privacy police in my company. Maybe you have some statistics on your side? I can send you project name from license.

vyakimchik commented 3 years ago

I'm not asking to provide the source code of the project you are working on - I'm asking for the demo project where there is only the necessary code of usage of our SDK so we can reproduce the issue that you arose. You can modify our project that is available in this repo if it's better for you. Unfortunately, at the moment we don't understand the source of the issue.

syakimchik commented 3 years ago

Hi @Reflector93 , Could you please check the version which users faced with this crash?

We have fixed this issue in API version 5.7.+. Now, we're not able to reproduce it.

Reflector93 commented 3 years ago

Hi @Reflector93 , Could you please check the version which users faced with this crash?

We have fixed this issue in API version 5.7.+. Now, we're not able to reproduce it.

Its true, on this version i don't have this error I change implementation of Regula in build.gradle(app Module) Now my implementation looks like implementation('com.regula.documentreader:api:5.7.4947') implementation 'com.regula.documentreader.core:ocrandmrz:5.7.5337'

syakimchik commented 3 years ago

@Reflector93,

Moreover, you can use '+' to get the latest version, but you should control the version of Regula SDK in your app. If you know a specific version, it can be easier to find issues on our side. When you're using '+', you also easily can find a version that was integrated into your current project. You can find it under 'External Libraries'.