1

在我的头撞到我的桌子上并雕刻了stackoverflow上的相关帖子之后,我不愿意发布这个问题,但就是无法解决问题。所以我们在这里。我正在尝试将ZXing集成到我的 Android 应用程序中,正如许多开发人员所尝试的那样,但一直遇到相同的错误:Unable to start activity ComponentInfo. 我添加了 core.jar 并将活动和相机权限添加到清单中。我知道我在这里缺少一些非常简单的事情要做。尝试使用意图进行扫描时出现以下错误。我已经尝试过浏览 ZXing 库并将所有 switch 语句更改为 if/else。我还尝试在 ZXing 布局中添加我的包名称,如下所示:Android ZXing implementation

爪哇:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainMenu extends Activity {

Button btn_scan

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);

    btn_scan = (Button) findViewById(R.id.btn_scanbarcode);
    btn_scan.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(
                    "com.google.zxing.client.android.SCAN");
            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");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

}

显现

<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>

日志猫:

11-30 10:54:04.713: E/AndroidRuntime(15452): FATAL EXCEPTION: main
11-30 10:54:04.713: E/AndroidRuntime(15452): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.testapp/com.google.zxing.client.android.CaptureActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2240)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2275)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.os.Looper.loop(Looper.java:156)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread.main(ActivityThread.java:5060)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at java.lang.reflect.Method.invokeNative(Native Method)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at java.lang.reflect.Method.invoke(Method.java:511)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at dalvik.system.NativeStart.main(Native Method)
11-30 10:54:04.713: E/AndroidRuntime(15452): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:278)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.Activity.setContentView(Activity.java:1897)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:143)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.Activity.performCreate(Activity.java:4543)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2196)
11-30 10:54:04.713: E/AndroidRuntime(15452):    ... 11 more
11-30 10:54:04.713: E/AndroidRuntime(15452): Caused by: java.lang.ClassNotFoundException: com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-30 10:54:04.713: E/AndroidRuntime(15452):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-30 10:54:04.713: E/AndroidRuntime(15452):    ... 21 more
4

2 回答 2

1

这里有几个问题,其中你试图在你的应用程序中声明我们的活动和命名空间。请不要这样做。它对您不起作用,并给我们的用户带来问题。

你似乎想这样做:https ://github.com/zxing/zxing/wiki/Scanning-Via-Intent

如果是这样,这比您在这里制作要容易得多。

于 2012-11-30T19:00:01.207 回答
1

您已将 zxing 项目作为库导入并删除不需要的类。这个过程很痛苦,但我得到了它的工作。

于 2013-01-04T22:30:33.960 回答