简体   繁体   中英

QR code scanner example code in processing from the QR code library not running on android phone

I am trying to run a code for qr code scanning in processing(version 3). I am using the already provided example code from the QR code library. I have installed the JDK 8 and android SDK as well, still not able to run the application on my android phone. It is getting installed but closes itself on running (shows "Unfortunately, QR code example has stopped") (I have tried a few other examples and it worked!).

I hereby add the code (which should be correct since it is an example code and I didn't make any changes) just for a reference and the errors which was displayed in the console as well. Since I am new to programming, I am not able to figure out what the error says exactly. Someone please have a look and help me out.

Thanks a lot in advance.

 /*
QRcode reader
 Generate images from a QRcode generator such as
 http://qrcode.kaywa.com/ and put them in this sketch's
 data folder.
 Press spacebar to read from the camera, generate an image,
 and scan for barcodes.  Press f to read from a file and scan.
 Press s for camera settings.
 Created 9 June 2007
 by Tom Igoe / Daniel Shiffman
 */


import processing.video.*;
import qrcodeprocessing.*;

Capture video;                                 // instance of the video capture library
String statusMsg = "Waiting for an image";     // a string to return messages:

// Decoder object from prdecoder library
Decoder decoder;

void setup() {
  size(400, 320);
  video = new Capture(this, 320, 240);
  video.start();

  // Create a decoder object
  decoder = new Decoder(this);
}

// When the decoder object finishes
// this method will be invoked.
void decoderEvent(Decoder decoder) {
  statusMsg = decoder.getDecodedString();
}

void captureEvent(Capture video) {
  video.read();
}

void draw() {
  background(0);

  // Display video
  image(video, 0, 0);
  // Display status
  text(statusMsg, 10, height-4);

  // If we are currently decoding
  if (decoder.decoding()) {
    // Display the image being decoded
    PImage show = decoder.getImage();
    image(show, 0, 0, show.width/4, show.height/4); 
    statusMsg = "Decoding image";
    for (int i = 0; i < (frameCount/2) % 10; i++) statusMsg += ".";
  }
}

void keyReleased() {
  // Depending on which key is hit, do different things:
  switch (key) {
  case ' ':        
    // Spacebar takes a picture and tests it:
    // copy it to the PImage savedFrame:
    PImage savedFrame = createImage(video.width, video.height, RGB);
    savedFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
    savedFrame.updatePixels();
    // Decode savedFrame
    decoder.decodeImage(savedFrame);
    break;
  case 'f':    // f runs a test on a file
    PImage preservedFrame = loadImage("qrcode.png");
    // Decode file
    decoder.decodeImage(preservedFrame);
    break;
  }
}

And here is the error report.

    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin
     [echo] org.eclipse.jdt.core.JDTCompilerAdapter

-set-mode-check:

-set-debug-files:

-check-env:
Android SDK Tools Revision 25.1.7
Installed at C:\Users\rahul\Documents\Processing\modes\AndroidMode\sdk

-setup:
     [echo] Project Name: QRCodeExample
Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
Using latest Build Tools: 24.0.0 rc4
     [echo] Resolving Build Target for QRCodeExample...
Project Target:   Android 6.0
API level:        23
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\rsObj
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\rsLibs
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\gen
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\classes
    [mkdir] Created dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for QRCodeExample...
Library dependencies:
No Libraries

------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
Merging AndroidManifest files into one.
Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 4 source files to C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\classes
----------
1. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 4)
    import processing.data.*; 
           ^^^^^^^^^^^^^^^
The import processing.data is never used
----------
2. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 5)
    import processing.event.*; 
           ^^^^^^^^^^^^^^^^
The import processing.event is never used
----------
3. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 6)
    import processing.opengl.*; 
           ^^^^^^^^^^^^^^^^^
The import processing.opengl is never used
----------
4. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 11)
    import java.util.HashMap; 
           ^^^^^^^^^^^^^^^^^
The import java.util.HashMap is never used
----------
5. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 12)
    import java.util.ArrayList; 
           ^^^^^^^^^^^^^^^^^^^
The import java.util.ArrayList is never used
----------
6. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 13)
    import java.io.File; 
           ^^^^^^^^^^^^
The import java.io.File is never used
----------
7. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 14)
    import java.io.BufferedReader; 
           ^^^^^^^^^^^^^^^^^^^^^^
The import java.io.BufferedReader is never used
----------
8. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 15)
    import java.io.PrintWriter; 
           ^^^^^^^^^^^^^^^^^^^
The import java.io.PrintWriter is never used
----------
9. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 16)
    import java.io.InputStream; 
           ^^^^^^^^^^^^^^^^^^^
The import java.io.InputStream is never used
----------
10. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 17)
    import java.io.OutputStream; 
           ^^^^^^^^^^^^^^^^^^^^
The import java.io.OutputStream is never used
----------
11. WARNING in C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\src\processing\test\qrcodeexample\QRCodeExample.java (at line 18)
    import java.io.IOException; 
           ^^^^^^^^^^^^^^^^^^^
The import java.io.IOException is never used
----------
11 problems (11 warnings)

-post-compile:

-obfuscate:

-dex:
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\classes
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\qrcodeprocessing.jar
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\gstreamer-java.jar
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\video.jar
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\jna.jar
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\processing-core.jar
input: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\qrcode.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\qrcodeprocessing.jar -> qrcodeprocessing-e0f68c0ac279966ab95e5f6515104871.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\gstreamer-java.jar -> gstreamer-java-d1933e0463161ece1a19c077f43e4ba6.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\video.jar -> video-e674dd3032ffd15eae0908334b2f493e.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\jna.jar -> jna-de64a2cde02c00ee2f942b718e389e21.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\processing-core.jar -> processing-core-51bd73b29340db555e7a49941792c93e.jar
Pre-Dexing C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\libs\qrcode.jar -> qrcode-6164974c3d18fd7eabc11f7143b49b00.jar
Converting compiled files and external libraries into C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\classes.dex...
       [dx] Merged dex #1 (8 defs/5.7KiB)
       [dx] Merged dex #2 (899 defs/521.6KiB)
       [dx] Merged dex #3 (107 defs/156.1KiB)
       [dx] Merged dex #4 (160 defs/684.4KiB)
       [dx] Merged dex #5 (31 defs/66.3KiB)
       [dx] Merged dex #6 (2 defs/3.6KiB)
       [dx] Merged dex #7 (12 defs/34.2KiB)
       [dx] Result is 1219 defs/1774.0KiB. Took 0.5s

-crunch:
   [crunch] Crunching PNG Files in source dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\res
   [crunch] To destination dir: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res
   [crunch] Processing image to cache: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\res\drawable-hdpi\icon.png => C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-hdpi\icon.png
   [crunch]   (processed image to cache entry C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-hdpi\icon.png: 47% size of source)
   [crunch] Processing image to cache: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\res\drawable-ldpi\icon.png => C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-ldpi\icon.png
   [crunch]   (processed image to cache entry C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-ldpi\icon.png: 0% size of source)
   [crunch] Processing image to cache: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\res\drawable-xhdpi\icon.png => C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-xhdpi\icon.png
   [crunch]   (processed image to cache entry C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable-xhdpi\icon.png: 32% size of source)
   [crunch] Processing image to cache: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\res\drawable\icon.png => C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable\icon.png
   [crunch]   (processed image to cache entry C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\res\drawable\icon.png: 0% size of source)
   [crunch] Crunched 4 PNG files to update cache

-package-resources:
Creating full resource package...
     [aapt] Warning: AndroidManifest.xml already defines debuggable (in http://schemas.android.com/apk/res/android); using existing value in manifest.

-package:
Current build type is different than previous build: forced apkbuilder run.
Creating QRCodeExample-debug-unaligned.apk and signing it with a debug key...

-post-package:

-do-debug:
Running zip align on final apk...
     [echo] Debug Package: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\QRCodeExample-debug.apk
[propertyfile] Creating new property file: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\build.prop
[propertyfile] Updating property file: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\build.prop
[propertyfile] Updating property file: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\build.prop
[propertyfile] Updating property file: C:\Users\rahul\AppData\Local\Temp\android8283714235284511395sketch\bin\build.prop

-post-build:

debug:
FATAL EXCEPTION: Animation Thread
Process: processing.test.qrcodeexample, PID: 26665
java.lang.NoSuchFieldError: processing.core.PApplet.platform
    at processing.video.Capture.<clinit>(Unknown Source)
    at processing.test.qrcodeexample.QRCodeExample.setup(QRCodeExample.java:46)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:841)
FATAL EXCEPTION: Animation Thread
Process: processing.test.qrcodeexample, PID: 28074
java.lang.NoSuchFieldError: processing.core.PApplet.platform
    at processing.video.Capture.<clinit>(Unknown Source)
    at processing.test.qrcodeexample.QRCodeExample.setup(QRCodeExample.java:46)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:841)
FATAL EXCEPTION: Animation Thread
Process: processing.test.qrcodeexample, PID: 28114
java.lang.NoSuchFieldError: processing.core.PApplet.platform
    at processing.video.Capture.<clinit>(Unknown Source)
    at processing.test.qrcodeexample.QRCodeExample.setup(QRCodeExample.java:46)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:841)

It looks like you're using a library that isn't compatible with Android.

Your code uses the Video library. The Video library uses a variable called platform . It can't find that variable, and that's why you're getting the error.

You say you're using the latest version of Processing, and looking at the code I do see a platform variable. However, looking at the code for Android Processing, I don't see the variable. That's what's causing your error.

You're going to have to find a library that's compatible with Android and then use that instead. Processing examples involving libraries will not automatically work in Android mode.

You're going to have to do some googling to find the library that's right for you. Good luck.

Finally, i found out that it is the sketch permissions that are causing my app to crash. Since i need to enable my camera for qr code scanning i have to enablr sketch permissions for camera. I am working on it now and will provide the complete solution soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM