Android Question JavaObject.SetField not working

Ross Wheeler

Member
Licensed User
Longtime User
I keep getting not found exceptions whenever I call any of the SetFields. This is just one example where I am trying to use the setNullQuietZoneAllowed = True but it doesn’t work.

<code>
Dim Pdf417RecognizerSettings As JavaObject
Pdf417RecognizerSettings.InitializeStatic("com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings")

Pdf417RecognizerSettings.SetField("setInverseScanning", True)
</code>

Is there something I am doing wrong?
If I change the Initialize and add in an extra or take away a character then it breaks so it is definitely the correct class I am referencing.

Classes.Jar https://www.dropbox.com/s/t00w84fx7sd40zu/Extracted Classes Jar.zip?dl=0
AAR https://www.dropbox.com/s/858lfpiotr0xmhs/LibPdf417Mobi.zip?dl=0
 

Attachments

  • PDF417Scanning.zip
    8.6 KB · Views: 137
  • PDF417.png
    PDF417.png
    55.1 KB · Views: 162

Ross Wheeler

Member
Licensed User
Longtime User
B4X:
    Dim Pdf417RecognizerSettings As JavaObject
    Pdf417RecognizerSettings.InitializeStatic("com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings")
    Pdf417RecognizerSettings.RunMethod("setNullQuietZoneAllowed", Array As Object(True))

Then I get this error.

Error occurred on line: 63 (Main)
java.lang.IllegalArgumentException: Expected receiver of type com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings, but got java.lang.Class<com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings>

If I use
B4X:
    Dim Pdf417RecognizerSettings As JavaObject
    Pdf417RecognizerSettings.InitializeStatic("com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings")
    Pdf417RecognizerSettings.RunMethod("setNullQuietZoneAllowed", Array As Object("True"))

Or

B4X:
    Pdf417RecognizerSettings.RunMethod("setNullQuietZoneAllowed", Array As Object(1))


I get error:
java.lang.RuntimeException: Method: setNullQuietZoneAllowed not matched.
 
Upvote 0

JordiCP

Well-Known Member
Licensed User
Longtime User
Perhaps
B4X:
 Pdf417RecognizerSettings.InitializeNewInstance("com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings",Null)
 Pdf417RecognizerSettings.RunMethod("setNullQuietZoneAllowed", ArrayAs Object("True"))

It is quite a complex (and powerful) SDK! Are you wrapping it all?
 
Upvote 0

Ross Wheeler

Member
Licensed User
Longtime User
Tried that and it returns

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/co.za.timelapsesys.pdf417-2/base.apk"],nativeLibraryDirectories=[/data/app/co.za.timelapsesys.pdf417-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libPdf417Mobi.so"

Which is the same error I get if I use the
B4X:
#IF JAVA
#End If

i can see the libPdf417Mobi.so file in the AAR in the jni\ directory.

I downloaded this SDK because I need to use PDF417 scanning for South African drivers license and vehicle registration discs so I am only referencing the AAR and hoping that it will work.
Have come so close yet so far
 
Upvote 0

JordiCP

Well-Known Member
Licensed User
Longtime User
Yes, I also got that when tried it later. But now the error is gone! :).

Changing code was just one part
B4X:
Pdf417RecognizerSettings.InitializeNewInstance("com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings",Null)
Pdf417RecognizerSettings.RunMethod("setNullQuietZoneAllowed", Array(True))

Now, the libraries:
  • Libraries are usually in a folder named "lib" and not "jni", which is for the native source code.
  • I renamed it in the aar file, but still didn't find it. Then made just a jar file with the lib folder and now it does not throw the error.
  • You can do the same (make a copy of the aar, rename the copy to .jar, open it with 7zip, remove all folders except "jni" and rename it to "lib")
  • If not, you can download the jar from this link: https://drive.google.com/file/d/0B-eBY3pamAunN3poangyUFZWR1k/view?usp=sharing
  • You will need to reference it also with #AdditionalJar

(I guess the lines below in the code will need to be changed in a similar way)

https://drive.google.com/file/d/0B-eBY3pamAunN3poangyUFZWR1k/view?usp=sharing
 
Upvote 0

Ross Wheeler

Member
Licensed User
Longtime User
Thank you.

That helped quite a bit. Unfortunately some of the other methods I needed were not working properly so went back to use JAVA

B4X:
#If JAVA
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.microblink.activity.Pdf417ScanActivity;
import com.microblink.recognizers.BaseRecognitionResult;
import com.microblink.recognizers.RecognitionResults;
import com.microblink.recognizers.blinkbarcode.BarcodeType;
import com.microblink.recognizers.blinkbarcode.bardecoder.BarDecoderRecognizerSettings;
import com.microblink.recognizers.blinkbarcode.bardecoder.BarDecoderScanResult;
import com.microblink.recognizers.blinkbarcode.pdf417.Pdf417RecognizerSettings;
import com.microblink.recognizers.blinkbarcode.pdf417.Pdf417ScanResult;
import com.microblink.recognizers.blinkbarcode.simnumber.SimNumberRecognizerSettings;
import com.microblink.recognizers.blinkbarcode.zxing.ZXingRecognizerSettings;
import com.microblink.recognizers.blinkbarcode.zxing.ZXingScanResult;
import com.microblink.recognizers.settings.RecognitionSettings;
import com.microblink.recognizers.settings.RecognizerSettings;
import com.microblink.results.barcode.BarcodeDetailedData;
import com.microblink.util.Log;
import com.microblink.view.recognition.RecognizerView;

import java.net.MalformedURLException;
import java.net.URL;

public void scancode() { 

Intent intent = new Intent(this, Pdf417ScanActivity.class);


        intent.putExtra(Pdf417ScanActivity.EXTRAS_LICENSE_KEY, "G75EO2HB-B3FSH2J4-CFEEE5DN-CRESTNSB-DSN7F6E3-6L4JX4XY-TPZPRG7S-7CN2GRH5");


        Pdf417RecognizerSettings pdf417RecognizerSettings = new Pdf417RecognizerSettings();
        pdf417RecognizerSettings.setNullQuietZoneAllowed(true);

        BarDecoderRecognizerSettings oneDimensionalRecognizerSettings = new BarDecoderRecognizerSettings();
       
        oneDimensionalRecognizerSettings.setScanCode39(true);
     
        oneDimensionalRecognizerSettings.setScanCode128(true);
        ZXingRecognizerSettings zXingRecognizerSettings = new ZXingRecognizerSettings();
     
        zXingRecognizerSettings.setScanQRCode(true);
        zXingRecognizerSettings.setScanITFCode(true);

     
        SimNumberRecognizerSettings sm = new SimNumberRecognizerSettings();

        RecognitionSettings recognitionSettings = new RecognitionSettings();

        recognitionSettings.setRecognizerSettingsArray(new RecognizerSettings[]{pdf417RecognizerSettings, oneDimensionalRecognizerSettings, zXingRecognizerSettings,sm});

        intent.putExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_SETTINGS, recognitionSettings);

        intent.putExtra(Pdf417ScanActivity.EXTRAS_ALLOW_PINCH_TO_ZOOM, true);

        intent.putExtra(Pdf417ScanActivity.EXTRAS_SHOW_FOCUS_RECTANGLE, true);

        startActivityForResult(intent, 1337);
}

#end if

This now works perfectly - It is scanning and message boxing the result which is correct.

Only issue I am stuck with now which I have searched the forums but nothing is helping is using

B4X:
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

Inside the Java Code.

I get this error.

error: method onActivityResult(int,int,Intent) is already defined in class main
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
^
Note: src\co\za\timelapsesys\pdf417\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
 
Upvote 0

Ross Wheeler

Member
Licensed User
Longtime User
I have tried to use the IOnActivityResult and it is not wanting to work.
As soon as i add this line
B4X:
private IOnActivityResult ion;

I get an error.

B4X:
B4A version: 6.50
Parsing code.    (0.00s)
Compiling code.    (0.08s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    (0.14s)
Compiling debugger engine code.    (0.71s)
Compiling generated Java code.    Error
javac 1.7.0_76
src\co\za\timelapsesys\pdf417\main.java:482: error: cannot find symbol
private IOnActivityResult ion;
        ^
  symbol:   class IOnActivityResult
  location: class main
Note: src\co\za\timelapsesys\pdf417\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

I am using Android 24
C:\Program Files (x86)\Android\android-sdk\platforms\android-24\android.jar

Please advise.

Thanks
 
Upvote 0

Ross Wheeler

Member
Licensed User
Longtime User
Add: import anywheresoftware.b4a.IOnActivityResult;

Thanks - This worked.

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.BA.startActivityForResult(anywheresoftware.b4a.IOnActivityResult, android.content.Intent)' on a null object reference

I am now getting this error.

B4X:
private BA ba;
private String eventName;
public void Initialize(BA ba, String EventName) {
 this.ba = ba;
 this.eventName = EventName.toLowerCase(BA.cul);

}

What type do I pass into the Initialize so that I can set the ba.
 
Upvote 0
Top