我正在使用zxing库,我使用Eclipse构建了ZXing Android,并在我的项目中包含了ZXing Android 和poject清单是
<?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)
答案 0 :(得分:0)
问题的原因在于CaptureActivity中的showHelpOnFirstLaunch()
方法。它试图获取com.google.zxing.client.android
包的版本,找不到它并抛出异常。它必须由catch (PackageManager.NameNotFoundException e) { ... }
捕获。我不知道为什么没有抓住异常。
您可以修改showHelpOnFirstLaunch()
方法,例如如果你的版本中没有它,请删除包版本的检查或添加异常捕获。