条形码扫描仪phonegap应用程序崩溃

时间:2014-06-19 11:28:08

标签: java android cordova phonegap-plugins

我试图在我的Android应用程序上安装条形码。当我调用条形码时,我的应用程序崩溃,我得到以下日志。请帮助我。提前谢谢。

06-19 16:50:45.913: W/dalvikvm(21407): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
06-19 16:50:45.953: E/AndroidRuntime(21407): FATAL EXCEPTION: main
06-19 16:50:45.953: E/AndroidRuntime(21407): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.crosslegged/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.os.Looper.loop(Looper.java:137)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread.main(ActivityThread.java:4441)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at java.lang.reflect.Method.invokeNative(Native Method)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at java.lang.reflect.Method.invoke(Method.java:511)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at dalvik.system.NativeStart.main(Native Method)
06-19 16:50:45.953: E/AndroidRuntime(21407): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
06-19 16:50:45.953: E/AndroidRuntime(21407):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
06-19 16:50:45.953: E/AndroidRuntime(21407):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
06-19 16:50:45.953: E/AndroidRuntime(21407):    ... 11 more
06-19 16:50:48.013: I/Process(21407): Sending signal. PID: 21407 SIG: 9

这是AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crosslegged"
android:versionCode="1"
android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
  <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:resizeable="true"
    android:anyDensity="true"
    />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"     />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
 <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
 <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>

<application
android:installLocation="auto"
    android:debuggable="true" 
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.crosslegged.MainActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <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"
        android:exported="false">
  <intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
 </intent-filter>
  </activity>
  </application>
 </manifest>

这是index.html

  <!DOCTYPE HTML>
  <html>
    <head>
      <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
       <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
       <title>My Barcode/QR Code Scanner</title>
       <style>
          body{
             background:#888888 none repeat scroll 0 0;
            }
          input[type='text']{
            width:18em;
            border:1px solid black;
        }
        input[type='button']{
            width:20em;
            border:1px solid black;
            color:#ffffff;
            font-family:"Times New Roman",Times,serif;
            font-size:0.9em;
            font-weight:bold;
            background:#737CA1;
        }
    </style>
    <script type="text/javascript" src="cordova-2.7.0.js"></script>
    <script type="text/javascript" src="barcodescanner.js"></script>
    <script type="text/javascript">
        function scanCode(){
            window.plugins.barcodeScanner.scan(
                function(result){
                    alert("Scanned Code: " + result.text 
                    + ". Format: " + result.format
                    + ". Cancelled: " + result.cancelled);
                }, 
                function(error){
                    alert("Scan failed: " + error);
                }
            );
        }

        function encodeData(){
            var data = document.getElementById("data").value;
            if (data != ''){
                window.plugins.barcodeScanner.encode(
                    BarcodeScanner.Encode.TEXT_TYPE, data, 
                    function(success){
                        alert("Encode success: " + success);
                    }, 
                    function(fail){
                        alert("Encoding failed: " + fail);
                    }
                );
            }
            else{
                alert("Please enter some data.");
                return false;
            }
        }
    </script>
</head>

<body>
    <h3>Barcode/QR Code Scanner And Encoder</h3>

    <input type="button" value="Scan Code" onclick="scanCode();"/><br/><br/>

    Data : <br/>
    <input type="text" name="data" id="data" /><br/><br/>
    <input type="button" value="Encode Data" onclick="encodeData();"/>
</body>

1 个答案:

答案 0 :(得分:0)

Unable to instantiate activity ComponentInfo{com.example.crosslegged/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity

应用程序活动路径搞砸了,CaptureActivity.java不存在或者Manifest中的路径不正确。

使用两个应用程序名称空间也没有意义。

com.example.crosslegged

com.google.zxing.client.android.CaptureActivity

活动路径应为:

com.example.crosslegged/ActivityA
com.example.crosslegged/ActivityB

依旧......