简体   繁体   English

来自QR码库的处理中的QR码扫描仪示例代码未在Android手机上运行

[英]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). 我正在尝试在处理(版本3)中运行用于QR码扫描的代码。 I am using the already provided example code from the QR code library. 我正在使用QR码库中已提供的示例代码。 I have installed the JDK 8 and android SDK as well, still not able to run the application on my android phone. 我还安装了JDK 8和android SDK,但仍然无法在android手机上运行该应用程序。 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!). 它正在安装中,但在运行时会自行关闭(显示“不幸的是,QR代码示例已停止”)(我尝试了其他一些示例,它确实起作用了!)。

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. 您似乎正在使用与Android不兼容的库。

Your code uses the Video library. 您的代码使用视频库。 The Video library uses a variable called platform . 视频库使用一个名为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. 您说您使用的是最新版本的Processing,并且在代码中确实看到了platform变量。 However, looking at the code for Android Processing, I don't see the variable. 但是, 查看Android Processing 的代码时 ,我看不到该变量。 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. 您将必须找到一个与Android兼容的库,然后改用它。 Processing examples involving libraries will not automatically work in Android mode. 处理涉及库的示例将无法在Android模式下自动运行。

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. 我现在正在努力,并将尽快提供完整的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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