-1

我正在使用 zxing 库,我在其中使用 Eclipse 构建了 ZXing Android 并将 ZXing Android 包含到我的项目中,并且项目清单是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="phoenix.metro.uis"
    android:versionCode="4"
    android:versionName="1.2" >

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:icon="@drawable/metro"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name="MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".PhoenixSplashActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="SearchActivity"
            android:multiprocess="false"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="OffersActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".CartsActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="GANDActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="MetroActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity android:name="AddItemActivity" >
        </activity>
        <activity
            android:name=".AboutUsActivity"
            android:screenOrientation="portrait" >
        </activity>
    </application>

</manifest>

但我得到了例外:

10-01 23:00:29.227: W/CaptureActivity(539): android.content.pm.PackageManager$NameNotFoundException: com.google.zxing.client.android
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ContextImpl$ApplicationPackageManager.getPackageInfo(ContextImpl.java:1682)
10-01 23:00:29.227: W/CaptureActivity(539):     at com.google.zxing.client.android.CaptureActivity.showHelpOnFirstLaunch(CaptureActivity.java:693)
10-01 23:00:29.227: W/CaptureActivity(539):     at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:169)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.os.Looper.loop(Looper.java:123)
10-01 23:00:29.227: W/CaptureActivity(539):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-01 23:00:29.227: W/CaptureActivity(539):     at java.lang.reflect.Method.invokeNative(Native Method)
10-01 23:00:29.227: W/CaptureActivity(539):     at java.lang.reflect.Method.invoke(Method.java:507)
10-01 23:00:29.227: W/CaptureActivity(539):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-01 23:00:29.227: W/CaptureActivity(539):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-01 23:00:29.227: W/CaptureActivity(539):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

问题的原因showHelpOnFirstLaunch()在于 CaptureActivity 中的方法。它试图获取com.google.zxing.client.android包的版本,没有找到它并抛出异常。它必须被抓住catch (PackageManager.NameNotFoundException e) { ... }。我不知道为什么没有捕获异常。

您可以编辑showHelpOnFirstLaunch()方法,例如删除包版​​本的检查或添加异常捕获(如果您的版本中没有)。

于 2012-10-02T17:36:54.337 回答