acktie / Acktie-Mobile-Android-Barcode

Acktie Mobile Barcode module is an easy to use yet powerful barcode reader.
Other
20 stars 13 forks source link

App force closes #5

Open skypanther opened 9 years ago

skypanther commented 9 years ago

Using essentially the code from your sample app the barcode scans, the barCodeWindow closes, and the module calls my success function (which opens a new window). Upon closing that window, I see the following in Monitor:

10-09 10:37:18.739: E/AndroidRuntime(15566): FATAL EXCEPTION: main
10-09 10:37:18.739: E/AndroidRuntime(15566): java.lang.NullPointerException
10-09 10:37:18.739: E/AndroidRuntime(15566):    at com.acktie.mobile.android.camera.CameraSurfaceView.surfaceCreated(CameraSurfaceView.java:87)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.SurfaceView.updateWindow(SurfaceView.java:569)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:231)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.View.dispatchWindowVisibilityChanged(View.java:7544)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1211)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.Choreographer.doFrame(Choreographer.java:532)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.os.Handler.handleCallback(Handler.java:725)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.os.Looper.loop(Looper.java:137)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at android.app.ActivityThread.main(ActivityThread.java:5041)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-09 10:37:18.739: E/AndroidRuntime(15566):    at dalvik.system.NativeStart.main(Native Method)
10-09 10:37:18.747: W/ActivityManager(379):   Force finishing activity com.myorg.demo/org.appcelerator.titanium.TiActivity

Further details:

var barcodescanner;
function showScanner() {
    barcodescanner = require("com.acktie.mobile.android.barcode");
    var CODE = [
        "CODE39",
        "CODE93",
        "CODE128",
    ];
    var options = {
        backgroundColor: 'black',
        width: '100%',
        height: '90%',
        top: 0,
        left: 0,
        allowZoom: true,
        userControlLight: false,
        barcodes: CODE,
        success: success,
        cancel: cancel,
        error: error
    };

    scanBarcodeFromCamera(options);
}

function success(e) {
    // async func here to look up the barcode and open 
    // new window on success. this works, however, closing
    // that new window shows the crash
    lookupBarcode(e.data, onSuccess, onError);
}

function scanBarcodeFromCamera(options) {
    var barcodeCodeWindow = Titanium.UI.createWindow({
        backgroundColor: 'black',
        width: '100%',
        height: '100%',
        theme: "Theme.AppCompat.NoTitleBar.Fullscreen"
    });
    var barcodeCodeView = barcodescanner.createBarcodeView(options);

    var closeButton = Titanium.UI.createButton({
        title: "Cancel",
        bottom: 0,
        left: 0
    });
    var lightToggle = Ti.UI.createSwitch({
        value: false,
        bottom: 0,
        right: 0
    });

    closeButton.addEventListener('click', function () {
        barcodeCodeView.stop();
        barcodeCodeWindow.close();
    });

    lightToggle.addEventListener('change', function () {
        barcodeCodeView.toggleLight();
    });

    barcodeCodeWindow.add(barcodeCodeView);
    barcodeCodeWindow.add(closeButton);

    if (options.userControlLight !== undefined && options.userControlLight) {
        barcodeCodeWindow.add(lightToggle);
    }

    // NOTE: Do not make the window Modal.  It screws stuff up.  Not sure why
    barcodeCodeWindow.open();
}
cjadhav commented 8 years ago

Hi @skypanther , Any luck on this issue. I am facing this issue only when user minimize and resumes the app.

skypanther commented 8 years ago

@cjadhav no, sorry. I gave up on this module. We're using the paid Scandit module. It's rather expensive, but is well supported, regularly updated, and actually works. (edit: sorry, that sounds like an ad for them which was not my intent)