基于cordova的Barcode Scanner混合应用程序中的运行时错误开发了工作灯6.1

时间:2014-02-25 18:22:28

标签: android cordova ibm-mobilefirst barcode-scanner

我正在关注此链接的教程

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>

1 个答案:

答案 0 :(得分:0)

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

您在此处未提及的另一件事是设置条形码扫描仪库项目。这与添加到Worklight项目中的Java不同。你也设置了这个吗? (虽然你得到的是另一个没有找到的课程)我实际上遇到了一个问题,我的Worklight项目没有拿到图书馆。我认为我的ADT工具存在问题,我无法正确设置库引用(它一直忘记设置)。我在一个新的Eclipse工作区中重新创建了项目,突然之间库被正确解析了。