Android Question Problem with zBarcodeScanner

David Elkington

Active Member
Licensed User
Longtime User
I was wondering if anyone could help. I have been using a barcode scanner in my app for ages, but now all of a sudden, I get an error when trying to initiate a scan. I have the error below, does anyone have any idea what is missing?

When I step though the code line by line, it seems to work

zb1.Visible = True
zb1.startScanner(backCamId)
b1.Visible=True



** Activity (mainmenu) Pause, UserClosed = false **
** Activity (qrallocation) Create, isFirst = true **
frontCamId = 1
backCamId = 0
** Activity (qrallocation) Resume **
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:255)
at android.content.res.Resources.getValue(Resources.java:1353)
at android.content.res.HwResources.getColor(HwResources.java:280)
at android.content.res.Resources.getColor(Resources.java:961)
at main.java.me.dm7.barcodescanner.core.ViewFinderView.<init>(ViewFinderView.java:39)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.createViewFinderView(BarcodeScannerView.java:57)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.setupLayout(BarcodeScannerView.java:40)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.setupCameraPreview(BarcodeScannerView.java:70)
at main.java.me.dm7.barcodescanner.core.CameraHandlerThread$1$1.run(CameraHandlerThread.java:31)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
 

Johan Schoeman

Expert
Licensed User
Longtime User

You are missing the resources. Extract the attached LibRes folder and its contents and make sure it is on the same folder level as that of your B4A project's /Files and /Objects folders. See extract of B4A code where LibRes is referenced

B4X:
#Region  Project Attributes
    #ApplicationLabel: ZbarBarcodeScanner
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False

#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

If you have this correct then it will work.

B4A manifest as what I have it:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
'AddManifestText(
'<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
'<supports-screens android:largeScreens="true"
'    android:normalScreens="true"
'    android:smallScreens="true"
'    android:anyDensity="true"/>)
'SetApplicationAttribute(android:icon, "@drawable/icon")
'SetApplicationAttribute(android:label, "$LABEL$")
'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.


'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
'AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
'AddPermission("android.permission.INTERNET")
'AddPermission("android.permission.ACCESS_FINE_LOCATION")
'AddPermission("android.permission.WAKE_LOCK")
'AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
'AddPermission("android.permission.READ_PHONE_STATE")
'AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
'AddPermission("android.hardware.camera")
'AddPermission("android.permission.INTERACT_ACROSS_USERS_FULL")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

'AddApplicationText(<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
'            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
'            android:windowSoftInputMode="stateAlwaysHidden">
'        </activity>)
 

Attachments

  • LibRes.zip
    1.1 KB · Views: 284
Upvote 0

figorra

Member
Licensed User
Longtime User
This is more or less my project.

One form to login

B4X:
#Region  Project Attributes
    #ApplicationLabel: NZero
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

    Dim Temporizador As Timer

End Sub

Sub Globals
    
    Private lblusuario As Label
    Private lblclave As Label
    Private txtusuario As EditText
    Private txtcodigo As Label
    Private txtclave As EditText
    Private login As Button
    Private salir As Button
    
    Dim loguear As HttpJob
    Dim res As String
    Dim parseo As JSONParser
    
    Dim forceClose As Boolean
    forceClose = False
    
    
    Dim Beep As Beeper
    Dim BeepMal As Beeper
    
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("login")
    loguear.Initialize("registro", Me)
    
    Dim cs As CSBuilder
    cs.Initialize.Size(20).Typeface(Typeface.SANS_SERIF)
    cs.Image(LoadBitmap(File.DirAssets, "nzero_p.jpg"), 30dip, 30dip, False).Append("  NZero")
    cs.BackgroundColor(Colors.Blue)
    cs.PopAll
    
    Temporizador.Initialize("Tiempo",2000)
    Temporizador.Enabled = False

    
    Activity.Title = cs
    Beep.Initialize(300, 500) '300 milliseconds, 500 hz
    BeepMal.Initialize(300, 800) '300 milliseconds, 500 hz

End Sub

Sub Tiempo_tick
    txtcodigo.Text = ""
    Temporizador.Enabled = False
End Sub

Sub Activity_Resume
    If forceClose Then ExitApplication
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub login_Click
    
    loguear.Download2("http://xxxx.xxxx/xxxx/aaaa.php", Array As String("username", txtusuario.Text, "password", txtclave.Text))
    
End Sub

Sub salir_Click
    
    forceClose = True
    Activity.Finish
    
End Sub

Sub JobDone (Job As HttpJob)
    
    If Job.Success Then
        
        res = Job.GetString
        
        parseo.Initialize(res)
        
        Select res
            
            Case "3"
                txtcodigo.Text = "Usuario no verificado"
                BeepMal.Beep
                
            Case "2"
                txtcodigo.Text = "Usuario desactivado"
                BeepMal.Beep

            Case "1"
                txtcodigo.Text = "Usuario Admitido"
                Beep.Beep
                StartActivity("Escaneo")

            Case "0"
                txtcodigo.Text = "Usuario o clave erronea"
                BeepMal.Beep
            
        End Select
        
        Temporizador.Enabled = True
        
    End If
    
End Sub

and Escaneo

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

    Private nativeMe As JavaObject

End Sub

Sub Globals
    
    Private zx1 As ZxingBarcodeScanner
    Private b1 As Button
    Private b2 As Button
    Private b3 As Button
    Private codigo As Label
    
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("escaner")
    
    nativeMe.InitializeContext
    
    zx1.LaserColor = Colors.Yellow
    zx1.MaskColor = Colors.ARGB(150, 0, 0, 200)
    zx1.BorderColor = Colors.Magenta
    zx1.BorderStrokeWidth = 5
    zx1.BorderLineLength = 40
    
    zx1.Visible = True
    zx1.startScanner

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

    zx1.Visible = False
    zx1.stopScanner
    
End Sub

Sub b1_Click
    
    zx1.toggleFlash
    
End Sub

Sub b2_Click
    
    zx1.Visible = True
    zx1.startScanner
    
End Sub

Sub b3_Click
    
    zx1.Visible = False
    zx1.stopScanner
    
End Sub

Sub zx1_scan_result (scantext As String, scanformat As String)
    
    Dim tim As Long = 100
    nativeMe.RunMethod("vibrateOnce", Array(tim))
    
    Log ("B4A scan text = " & scantext)
    Log ("B4A scan format = " & scanformat)
    codigo.Text = scantext
    
End Sub

#If Java

import android.os.Vibrator;
import android.content.Context;

/**
*Vibrate with a given pattern.
*Pass in an array of Longs that are the durations for which to turn on or off the vibrator in milliseconds.
*The first value indicates the number of milliseconds to wait before turning the vibrator on. The next
*value indicates the number of milliseconds for which to keep the vibrator on before turning it off.
*Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
*Parameters:
*pattern ---> an array of longs of times for which to turn the vibrator on or off.
*repeat ---> the index into pattern at which to repeat, or -1 if you don't want to repeat.
*
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*/
public void vibratePattern(long[] pattern, int repeat) {
    
  Vibrator v = (Vibrator) BA.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
  if (v.hasVibrator()) {
    v.vibrate(pattern, repeat);
  }
}

/**
*Cancel vibration (in case of method vibratePattern being active)
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*
*/
public void vibrateCancel(int dummy) {
    
  Vibrator v = (Vibrator) BA.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
  if (v.hasVibrator()) {
     v.cancel();
  }
}

/**
*Vibrate continuously for the specified number of milliseconds
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*/
public void vibrateOnce(long duration) {
    
  Vibrator v = (Vibrator) BA.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
  if (v.hasVibrator()) {
     v.vibrate(duration);
  }
}

#End If

The libraries are



This second code is from

b4aZxingBarcodeScanner post and work when I use the example. But when I use on my project have this error

*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (escaneo) Create, isFirst = true **
** Activity (escaneo) Resume **
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.getColor(Resources.java:964)
at android.content.res.Resources.getColor(Resources.java:940)
at main.java.me.dm7.barcodescanner.core.ViewFinderView.<init>(ViewFinderView.java:39)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.createViewFinderView(BarcodeScannerView.java:57)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.setupLayout(BarcodeScannerView.java:40)
at main.java.me.dm7.barcodescanner.core.BarcodeScannerView.setupCameraPreview(BarcodeScannerView.java:70)
at main.java.me.dm7.barcodescanner.core.CameraHandlerThread$1$1.run(CameraHandlerThread.java:31)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

and close de app
 

Attachments

  • librerias.png
    librerias.png
    7.1 KB · Views: 354
Upvote 0

figorra

Member
Licensed User
Longtime User
You are missing the resources. Extract the attached LibRes folder and its contents and make sure it is on the same folder level as that of your B4A project's /Files and /Objects folders. See extract of B4A code where LibRes is referenced

B4X:
#Region  Project Attributes
    #ApplicationLabel: ZbarBarcodeScanner
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False

#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

If you have this correct then it will work.

B4A manifest as what I have it:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
'AddManifestText(
'<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
'<supports-screens android:largeScreens="true"
'    android:normalScreens="true"
'    android:smallScreens="true"
'    android:anyDensity="true"/>)
'SetApplicationAttribute(android:icon, "@drawable/icon")
'SetApplicationAttribute(android:label, "$LABEL$")
'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.


'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
'AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
'AddPermission("android.permission.INTERNET")
'AddPermission("android.permission.ACCESS_FINE_LOCATION")
'AddPermission("android.permission.WAKE_LOCK")
'AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
'AddPermission("android.permission.READ_PHONE_STATE")
'AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
'AddPermission("android.hardware.camera")
'AddPermission("android.permission.INTERACT_ACROSS_USERS_FULL")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

'AddApplicationText(<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
'            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
'            android:windowSoftInputMode="stateAlwaysHidden">
'        </activity>)


WORK PERFECTLY

THANKS SO MUCH
 
Upvote 0
Top