簡體   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