B4A Library [class] Google Code Scanner - no permission, very simple to use, barcode scanning

Mark Stuart

Active Member
Licensed User
Longtime User
Put a button on the layout and pasted the above code into its click function.
Changed the "formats" to Scanner.FORMAT_CODE_128

Ran the app successfully to the tablet and the google scan layout appeared with the camera and a rounded color corner square appeared also.

Put the camera over a barcode and waited. The scanner layout zoomed in and out with no reporting/logging to the Logs.

Pressed on the upper left X button and the app closed with the following error lines in the IDE:
B4X:
Logger connected to:  samsung SM-T380
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
Back in B4A : Modules are present on the device
Error occurred on line: 47 (GoogleCodeScanner)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA$SharedProcessBA anywheresoftware.b4a.BA.sharedProcessBA' on a null object reference
    at anywheresoftware.b4a.B4AClass$ImplB4AClass.getActivityBA(B4AClass.java:37)
    at com.mfs.barcodescanner_demo.googlecodescanner$ResumableSub_Scan.resume(googlecodescanner.java:330)
    at com.mfs.barcodescanner_demo.googlecodescanner._scan(googlecodescanner.java:113)
    at com.mfs.barcodescanner_demo.main$ResumableSub_btnScan_Click.resume(main.java:450)
    at com.mfs.barcodescanner_demo.main._btnscan_click(main.java:422)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7357)
    at android.widget.TextView.performClick(TextView.java:14263)
    at android.view.View.performClickInternal(View.java:7323)
    at android.view.View.access$3200(View.java:849)
    at android.view.View$PerformClick.run(View.java:27884)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
** Activity (main) Pause, UserClosed = false **
What am I doing wrong?
 

Magma

Expert
Licensed User
Longtime User
Well... i ve recreated.... in b4xpages ...don't know if has something to do with views... (Activity)
but in b4xpages working... attaching project

Have in mind to change project name ( i remember you don't like b4x example )

Works perfect in Android 12 (Samsung A12)
Also tested in Bluestacks 5 (Android 7)

Happy Coding !
 

Attachments

  • barcodescanner.zip
    17.4 KB · Views: 3
Cookies are required to use this site. You must accept them to continue using the site. Learn more…