繁体   English   中英

基于Cordova的Barcode Scanner混合应用开发的Worklight 6.1中的运行时错误

[英]Runtime error in cordova based Barcode Scanner hybrid app developed worklight 6.1

我正在此链接上关注教程

https://www.ibm.com/developerworks/community/blogs/WASFAQs/entry/using_a_barcode_scanner_with_worklight?lang=en

通过它我可以使用Worklight 6.1开发条形码扫描仪。 但是按照本教程的步骤操作后,我在logcat中遇到了以下错误。

**02-25 04:33:05.013: D/AndroidRuntime(811): Shutting down VM
02-25 04:33:05.013: W/dalvikvm(811): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
02-25 04:33:05.023: E/AndroidRuntime(811): FATAL EXCEPTION: main
02-25 04:33:05.023: E/AndroidRuntime(811): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.BarcodeScannerSampleApp/com.BarcodeScannerSampleApp.BarcodeScannerSampleApp}: java.lang.ClassNotFoundException: Didn't find class "com.BarcodeScannerSampleApp.BarcodeScannerSampleApp" on path: DexPathList[[zip file "/data/app/com.BarcodeScannerSampleApp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.BarcodeScannerSampleApp-2, /system/lib]]
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.os.Looper.loop(Looper.java:137)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread.main(ActivityThread.java:5103)
02-25 04:33:05.023: E/AndroidRuntime(811):  at java.lang.reflect.Method.invokeNative(Native Method)
02-25 04:33:05.023: E/AndroidRuntime(811):  at java.lang.reflect.Method.invoke(Method.java:525)
02-25 04:33:05.023: E/AndroidRuntime(811):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-25 04:33:05.023: E/AndroidRuntime(811):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-25 04:33:05.023: E/AndroidRuntime(811):  at dalvik.system.NativeStart.main(Native Method)
02-25 04:33:05.023: E/AndroidRuntime(811): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.BarcodeScannerSampleApp.BarcodeScannerSampleApp" on path: DexPathList[[zip file "/data/app/com.BarcodeScannerSampleApp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.BarcodeScannerSampleApp-2, /system/lib]]
02-25 04:33:05.023: E/AndroidRuntime(811):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
02-25 04:33:05.023: E/AndroidRuntime(811):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-25 04:33:05.023: E/AndroidRuntime(811):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-25 04:33:05.023: E/AndroidRuntime(811):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
02-25 04:33:05.023: E/AndroidRuntime(811):  ... 11 more**

AndroidManifest.xml如下所示:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.BarcodeScannerSampleApp" android:versionCode="1" android:versionName="1.0">  
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>  
<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/>  
<uses-permission android:name="android.permission.INTERNET"/>  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
<!-- Push permissions -->  
<permission android:name="com.BarcodeScannerSampleApp.permission.C2D_MESSAGE" android:protectionLevel="signature"/>  
<uses-permission android:name="com.BarcodeScannerSampleApp.permission.C2D_MESSAGE"/>  
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>  
<uses-permission android:name="android.permission.WAKE_LOCK"/>  
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>  
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>  
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 


<!-- Adding camera permission here -->
<uses-permission android:name="android.permission.CAMERA"/>
<!-- abcdefgh -->

<application android:label="@string/app_name" android:debuggable="true" android:icon="@drawable/icon"> 
    <activity android:name=".BarcodeScannerSampleApp" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask"> 
        <intent-filter> 
            <action android:name="android.intent.action.MAIN"/>  
            <category android:name="android.intent.category.LAUNCHER"/> 
        </intent-filter>  
        <intent-filter> 
            <action android:name="com.BarcodeScannerSampleApp.BarcodeScannerSampleApp.NOTIFICATION"/>  
            <category android:name="android.intent.category.DEFAULT"/> 
        </intent-filter> 
    </activity>  
     <!-- ADDING CARdova support files here -->
    <activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter> 
            <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
                <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter> 
    </activity>
    <activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="@string/share_name">
        <intent-filter> 
            <action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
            <category android:name="android.intent.category.DEFAULT"/> 
        </intent-filter>            
    </activity>
    <!-- abcdefgh -->
    <!-- Preference Activity  -->  
    <activity android:name="com.worklight.common.WLPreferences" android:label="Worklight Settings"></activity>  
    <!-- Push service  -->  
    <!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver 
        It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->  
    <service android:name=".GCMIntentService"/>  
    <service android:name=".ForegroundService"/>  
    <!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->  
    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
        <!-- Receive the actual message -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>  
            <category android:name="com.BarcodeScannerSampleApp"/> 
        </intent-filter>  
        <!-- Receive the registration id -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>  
            <category android:name="com.BarcodeScannerSampleApp"/> 
        </intent-filter> 
    </receiver> 





</application> 

我将以下代码段添加到config.xml文件中

<feature name="BarcodeScanner">
    <param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
</feature> 

存在于app / BarcodeScannerSampleApp / common /中的index.html文件

<!DOCTYPE HTML>
<html>
        <head>
            <meta charset="UTF-8">
            <title>index</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
            <link rel="shortcut icon" href="images/favicon.png">
            <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
            <link rel="stylesheet" href="css/main.css">
            <script>window.$ = window.jQuery = WLJQ;</script>
        </head>
        <body >

            <!--application UI goes here-->
            <h1>Barcode scanner</h1>
            <button type="button" id="scanButton">Scan</button>

        <script>
        $('#scanButton').bind('click', doScan);

        function doScan()
            {
                cordova.exec(onScanSuccess, onScanFailure, 'BarcodeScanner', 'scan', []);
            }

        function onScanSuccess(result)
         {
            alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
         }

        function onScanFailure(error)
         {
            alert("Scanning failed: " + error);
         }
        </script>
        </body>
</html>

这似乎很奇怪,因为它是找不到的Worklight应用程序的默认Java类,而不是条形码扫描仪本身。 具有Android目标环境的简单应用程序是否可以正确启动?

您此处未提及的另一件事是设置条形码扫描器库项目。 这与添加到Worklight项目中的Java不同。 您也设置了吗? (尽管您会为此找到一个不同的类),但实际上我的一个问题是我的Worklight项目没有使用该库。 我认为ADT工具有一个问题,我无法正确设置库引用(它会忘记设置)。 我在新的Eclipse工作区中重新创建了项目,然后突然库被正确解析。

暂无
暂无

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

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