gpt4 book ai didi

android - 将zxing导入现有项目

转载 作者:行者123 更新时间:2023-11-30 03:57:23 26 4
gpt4 key购买 nike

我试图将ZXing导入到当前正在开发的android应用中,但是每当我尝试启动活动时,它就会崩溃。

 public void bcreader(View view)
{
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
}
}
}


左侧有ZXing源代码提供的MainActivity。
我遵循了 this教程,但无济于事。
我确保已导入所有文件,并将com.google.zxing ...设置为库等。
我还确保manifest.xml具有适当的授予的权限。

谁能告诉我我在做什么错?

错误日志:
10-30 00:26:06.919:D / AndroidRuntime(4194):关闭VM
10-30 00:26:06.919:W / dalvikvm(4194):threadid = 1:线程以未捕获的异常退出(group = 0x40a261f8)
10-30 00:26:06.919:E / AndroidRuntime(4194):致命异常:主
10-30 00:26:06.919:E / AndroidRuntime(4194):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.google.zxing.client.android/com.google.zxing.client.android.CaptureActivity} :java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
10-30 00:26:06.919:E / AndroidRuntime(4194):at android.app.ActivityThread.access $ 600(ActivityThread.java:132)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1157)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.os.Handler.dispatchMessage(Handler.java:99)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.os.Looper.loop(Looper.java:137)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.ActivityThread.main(ActivityThread.java:4575)
10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.reflect.Method.invokeNative(本机方法)
10-30 00:26:06.919:E / AndroidRuntime(4194):at java.lang.reflect.Method.invoke(Method.java:511)
10-30 00:26:06.919:E / AndroidRuntime(4194):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-30 00:26:06.919:E / AndroidRuntime(4194):在dalvik.system.NativeStart.main(本机方法)
10-30 00:26:06.919:E / AndroidRuntime(4194):原因:java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity
10-30 00:26:06.919:E / AndroidRuntime(4194):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.Instrumentation.newActivity(Instrumentation.java:1023)
10-30 00:26:06.919:E / AndroidRuntime(4194):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
10-30 00:26:06.919:E / AndroidRuntime(4194):...还有11个
10-30 00:29:27.799:D / AndroidRuntime(4407):关闭VM
10-30 00:29:27.799:W / dalvikvm(4407):threadid = 1:线程以未捕获的异常退出(group = 0x40a261f8)
10-30 00:29:27.799:E / AndroidRuntime(4407):致命异常:主
10-30 00:29:27.799:E / AndroidRuntime(4407):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.google.zxing.client.android/com.google.zxing.client.android.CaptureActivity} :java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
10-30 00:29:27.799:E / AndroidRuntime(4407):at android.app.ActivityThread.access $ 600(ActivityThread.java:132)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1157)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.os.Handler.dispatchMessage(Handler.java:99)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.os.Looper.loop(Looper.java:137)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.ActivityThread.main(ActivityThread.java:4575)
10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.reflect.Method.invokeNative(本机方法)
10-30 00:29:27.799:E / AndroidRuntime(4407):at java.lang.reflect.Method.invoke(Method.java:511)
10-30 00:29:27.799:E / AndroidRuntime(4407):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)
10-30 00:29:27.799:E / AndroidRuntime(4407):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-30 00:29:27.799:E / AndroidRuntime(4407):在dalvik.system.NativeStart.main(本机方法)
10-30 00:29:27.799:E / AndroidRuntime(4407):原因:java.lang.ClassNotFoundException:com.google.zxing.client.android.CaptureActivity
10-30 00:29:27.799:E / AndroidRuntime(4407):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.Instrumentation.newActivity(Instrumentation.java:1023)
10-30 00:29:27.799:E / AndroidRuntime(4407):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
10-30 00:29:27.799:E / AndroidRuntime(4407):...还有11个

最佳答案

将以下内容添加到清单中。

        <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="com.google.zxing.client.android.encode.EncodeActivity"
android:configChanges="orientation|keyboardHidden"
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.ENCODE" />

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

关于android - 将zxing导入现有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com