抱歉我的英文。我尝试多次包括libruary ZXing扫描qr代码。但不是成功的。我从this下载libruary然后我添加eclipse并包含core.jar并检查Android libruary。然后我在我的应用程序中添加libruary ZXing文件夹,但我有这个错误:
05-18 20:34:59.504: W/dalvikvm(19141): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
05-18 20:34:59.504: W/dalvikvm(19141): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
05-18 20:34:59.504: D/AndroidRuntime(19141): Shutting down VM
05-18 20:34:59.504: W/dalvikvm(19141): threadid=1: thread exiting with uncaught exception (group=0x40d4b258)
05-18 20:34:59.509: E/AndroidRuntime(19141): FATAL EXCEPTION: main
05-18 20:34:59.509: E/AndroidRuntime(19141): java.lang.ExceptionInInitializerError
05-18 20:34:59.509: E/AndroidRuntime(19141): at java.lang.Class.newInstanceImpl(Native Method)
05-18 20:34:59.509: E/AndroidRuntime(19141): at java.lang.Class.newInstance(Class.java:1319)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1992)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.ActivityThread.access$600(ActivityThread.java:134)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.os.Looper.loop(Looper.java:154)
05-18 20:34:59.509: E/AndroidRuntime(19141): at android.app.ActivityThread.main(ActivityThread.java:4624)
05-18 20:34:59.509: E/AndroidRuntime(19141): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 20:34:59.509: E/AndroidRuntime(19141): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 20:34:59.509: E/AndroidRuntime(19141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
05-18 20:34:59.509: E/AndroidRuntime(19141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
05-18 20:34:59.509: E/AndroidRuntime(19141): at dalvik.system.NativeStart.main(Native Method)
05-18 20:34:59.509: E/AndroidRuntime(19141): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
05-18 20:34:59.509: E/AndroidRuntime(19141): at com.google.zxing.client.android.CaptureActivity.<clinit>(CaptureActivity.java:93)
05-18 20:34:59.509: E/AndroidRuntime(19141): ... 15 more
我的主要活动:
public class MainActivity extends Activity {
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(ACTION_SCAN);
//intent.setPackage("com.example.bonsitemanager");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.e(contents, contents);
Log.e(format, format);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("App","Scan unsuccessful");
}
}
}
}
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bonsiteqr"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:1)
在eclipse中逐步设置zxing 3.2.1