ZXing Tutorial Issues

1,062 views
Skip to first unread message

Greg

unread,
Jun 6, 2011, 12:40:34 AM6/6/11
to Eclipse Plugin for PhoneGap
Hello everyone,

I followed the tutorial step by step and was able to compile just
fine. Great job on the tutorial. I am running the app on a samsung
galaxy on 2.1-update1. The app opens on my phone fine but when
pressing the buttons, no response.

I added an alert msg before the barcode call, inside the function, and
it alerts the message so something is not working correctly with the
zxing aspect.

I'm new to android/phonegap so I will need some guidance accessing the
log files if that is needed. Please help me get the barcode scanner
working!

Thanks

Greg

unread,
Jun 6, 2011, 1:18:11 AM6/6/11
to Eclipse Plugin for PhoneGap
I got the logcat, and the error is because the plugin is not getting
created as a suspected..

D/PhoneGapLog( 4623): file:///android_asset/www/main.js: Line 13 :
TypeError: Result of expression
'window.plugins.barcodeScanner' [undefined] is not an object.

Okay, so after more research the problem is that the index.html in the
tutorial includes main.js and barcodescanner.js before loading
phonegap which triggers an error in reigstering the phonegap plugin
because phonegap hasn't been created yet! So anyone else following the
tutorial it seems necessary to include phonegap before the other 2 js
files

Elizabeth Baldwin

unread,
Jun 6, 2011, 1:47:26 AM6/6/11
to eclipse-plugi...@googlegroups.com
Hi Greg.  Good work. I'm sorry about the lack of specific instruction
around the JavaScript files in index.html. I hope all is fine and working
for you now.

I've updated the section of the tutorial to be more clear. Thanks again
for your feedback!

Cheers,
Libby

Greg

unread,
Jun 6, 2011, 12:54:16 PM6/6/11
to Eclipse Plugin for PhoneGap
Great job Libby! Like I said before, the tutorial was great and easy
to follow. The pictures, ui (colors/layout), and the descriptions used
in the tutorial made for a great tutorial.

namr...@gmail.com

unread,
May 29, 2012, 8:48:21 PM5/29/12
to eclipse-plugi...@googlegroups.com
Hi,

I am still getting the error
"05-30 00:34:19.034: E/Web Console(368): TypeError: Result of expression 'window.plugins.barcodeScanner' [undefined] is not an object. at file:///android_asset/www/main.js:2"
 inspite of adding the phonegap.js file first, barcodescanner.js file next and main.js file at the end.
Could you please let me know what the error could be?

Thanks & Regards,
Smitha

Elizabeth Baldwin

unread,
May 29, 2012, 10:11:18 PM5/29/12
to eclipse-plugi...@googlegroups.com
Hi Smitha. Please verify that you do have barcoderscanner.js
in assset/www, and double check that the two <activity>'s
are inside the <application> tag in AndroidManifest.xml.

If you created main.js by hand, instead of using the provided,
please check for differences.

Libby

Smitha Kamath

unread,
May 29, 2012, 11:05:33 PM5/29/12
to eclipse-plugi...@googlegroups.com
Hi Libby,

Thank you for the immediate response.
I checked all these points you had mentioned, and they all seem to be fine.

Let me tell you a couple of more changes I have done.
In the BarcodeScanner.java class I have changed the imports from  "import org.apache.cordova.api.Plugin; and 
import org.apache.cordova.api.PluginResult;" to "import com.phonegap.api.Plugin; and 
import com.phonegap.api.PluginResult;"
And in the logcat i get the error 
"05-30 02:58:10.140: E/Web Console(387): ReferenceError: Can't find variable: cordova at file:///android_asset/www/barcodescanner.js:57"

But it runs fine beyond the error and launches the app.When I click on the Scan Code/ Encode Text options in the app, I get the error
"05-30 00:34:19.034: E/Web Console(368): TypeError: Result of expression 'window.plugins.barcodeScanner' [undefined] is not an object. at file:///android_asset/www/main.js:2" 

Is it in anyway linked to cordova issue.If that's so, please could you let me know as to how I could resolve the import issue wrt Cordova.

Thanks again for your help!!
Regards,
Smitha

Elizabeth Baldwin

unread,
May 30, 2012, 12:42:03 AM5/30/12
to eclipse-plugi...@googlegroups.com
Hi, and you're welcome. I should have asked which
version of PhoneGap you are using. In any case,
make sure you are pulling the corresponding repo
from github, that is to say refer to the tutorial for the
different versions of phonegap-plugins on github.

I believe you have made the right changes, but see my
summary below from two projects I have created and
tested with two different versions.

PhoneGap 1.4.1, BarcodeScanner.java:
package com.phonegap.plugins.barcodescanner;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

PhoneGap 1.5.0+ (e.g. Cordova 1.6.1), BarcodeScanner.java:
package com.phonegap.plugins.barcodescanner;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

You may have mixed the versions. The barcodescanner.js
that goes with PhoneGap 1.5.0+ will have a line like this in it (new way):
    cordova.exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', []);

PhoneGap 1.4.1 will have a line like this in it (old way):
    PhoneGap.exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', []);

Libby

Smitha Kamath

unread,
May 30, 2012, 1:27:28 PM5/30/12
to eclipse-plugi...@googlegroups.com
Hi Libby,

Thanks again and this time it worked. :)
The mistake i had done was that I had taken the Cordova version of "barcodescanner.js" and placed it in my  PhoneGap 1.4.1  project.
When I placed the correct file, it worked fine.

Thanks again!!
Smitha

Libby

unread,
May 30, 2012, 4:46:23 PM5/30/12
to eclipse-plugi...@googlegroups.com
Great, Smitha! Thanks for letting us know.

With the release of Cordova 2.0 this summer, I hope to unify
and simplify all the tutorials.

Cheers,
Libby

Smitha Kamath

unread,
May 31, 2012, 8:01:33 PM5/31/12
to eclipse-plugi...@googlegroups.com
Thank you Libby.your tutorials are great :)
Regards,
Smitha

karthik dheeraj

unread,
Jul 10, 2013, 11:08:25 AM7/10/13
to eclipse-plugi...@googlegroups.com, t2bi...@gmail.com
Hi Greg..

I am trying to develop barcode scanning application.. Can u please help me out to start the application development in android... Provide some links for it
----------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages