1

我正在尝试在 Eclipse 中使用 sdk 创建一个应用程序,其中包含一个独立的 qr 扫描仪。我遵循了一个非常好的教程来合并 zxing 并复制了所有相关库等,但是在设备上运行扫描仪时,我不断收到错误“不幸的是,项目名称已停止工作”。我是创建应用程序的新手,没有理解错误和纠正的词汇。我认为这是清单的问题....

03-19 15:32:05.129: D/TextLayoutCache(9760): Using debug level: 0 - Debug Enabled: 0
03-19 15:32:05.169: D/libEGL(9760): loaded /system/lib/egl/libGLES_android.so
03-19 15:32:05.189: D/libEGL(9760): loaded /system/lib/egl/libEGL_mali.so
03-19 15:32:05.199: D/libEGL(9760): loaded /system/lib/egl/libGLESv1_CM_mali.so
03-19 15:32:05.199: D/libEGL(9760): loaded /system/lib/egl/libGLESv2_mali.so
03-19 15:32:05.219: D/OpenGLRenderer(9760): Enabling debug mode 0
03-19 15:32:10.074: D/AndroidRuntime(9760): Shutting down VM
03-19 15:32:10.074: W/dalvikvm(9760): threadid=1: thread exiting with uncaught exception (group=0x40aae210)
03-19 15:32:10.084: E/AndroidRuntime(9760): FATAL EXCEPTION: main
03-19 15:32:10.084: E/AndroidRuntime(9760): java.lang.IllegalStateException: Could not execute method of the activity
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.view.View$1.onClick(View.java:3103)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.view.View.performClick(View.java:3574)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.view.View$PerformClick.run(View.java:14293)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.os.Handler.handleCallback(Handler.java:605)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.os.Looper.loop(Looper.java:137)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.app.ActivityThread.main(ActivityThread.java:4448)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at java.lang.reflect.Method.invoke(Method.java:511)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at dalvik.system.NativeStart.main(Native Method)
03-19 15:32:10.084: E/AndroidRuntime(9760): Caused by: java.lang.reflect.InvocationTargetException
03-19 15:32:10.084: E/AndroidRuntime(9760):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at java.lang.reflect.Method.invoke(Method.java:511)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.view.View$1.onClick(View.java:3098)
03-19 15:32:10.084: E/AndroidRuntime(9760):     ... 11 more
03-19 15:32:10.084: E/AndroidRuntime(9760): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at android.app.Activity.startActivityForResult(Activity.java:3190)
03-19 15:32:10.084: E/AndroidRuntime(9760):     at com.example.scanner.MainActivity.scanNow(MainActivity.java:28)
03-19 15:32:10.084: E/AndroidRuntime(9760):     ... 14 more

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.scanner"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.scanner.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>
    </application>

</manifest>

和主要活动

package com.example.scanner;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void scanNow(View view){
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("com.google.zxing.client.android.SCAN.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.i("xZing", "contents: "+contents+" format: "+format);
                // Handle successful scan        
                //else if (resultCode == RESULT_CANCELED)
                // Handle cancel  Log.i("xZing", "Cancelled");
            }
        }
    }
}

如果有人能指出我正确的方向,我将永远感激

干杯

4

1 回答 1

0

您需要安装条形码扫描仪。如果您使用了提供的,IntentIntegrator这将为您完成:https ://code.google.com/p/zxing/wiki/ScanningViaIntent并正确处理。您不需要清单条目即可使用相机等。

于 2013-03-19T17:10:40.670 回答