gpt4 book ai didi

java - Zxing 库应用程序集成运行时异常 ClassNotFoundException

转载 作者:行者123 更新时间:2023-11-29 05:28:28 26 4
gpt4 key购买 nike

我尝试将 zxing-Library 集成到 Android 应用程序中,因此用户不必安装 zxing。

我做了什么:

  • 下载Zxing-2.2.zip
  • 创建自己的 build.xml(在 core/... 中没有):

    <?xml version="1.0" encoding="utf-8" ?>
    <project name="core" default="jar" basedir=".">
    <target name="compile" description="Compile source">
    <mkdir dir="bin" />
    <javac srcdir="src" includes="**" destdir="bin"/>
    <copy todir="bin">
    <fileset dir="src" />
    </copy>
    </target>
    <target name="jar" description="Package into JAR" depends="compile">
    <jar destfile="core.jar" basedir="bin" compress="true" />
    </target>
    </project>
  • 使用 ant -f core/build.xml

    创建一个 core.jar
  • 在 Eclipse 中从现有代码创建 Android 项目
  • 在 eclipse 中为 core.jar(“libs”)创建文件夹
  • 在里面粘贴 jar
  • 还在调用 zxing-lib 的应用程序中执行最后 2 个步骤
  • 在“xzing-lib-app”首选项中 => android => 检查为库
  • 在调用应用程序首选项中 => android => 库 => 添加 => "xzing-lib-app"

我也尝试过:

  • 通过配置构建路径将 core.jar 添加到库中(除了自动添加的)
  • 在导出选项卡上设置复选框
  • 将图书馆移动到顶部
  • 清理这两个项目
  • ...

这是出现错误的上半部分

02-21 11:34:55.055: E/AndroidRuntime(8797): FATAL EXCEPTION: main
02-21 11:34:55.055: E/AndroidRuntime(8797): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hit.scantohit/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity

list :

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

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

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

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.hit.scantohit.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

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

<data
android:host="scanclinet"
android:scheme="hitscheme" />
<!-- myscheme://myhost ==> hitscheme://scanclinet -->
</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="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>
</application>
</manifest>

布局 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
android:id="@+id/btn_start_hit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_start_scan"
android:layout_alignBottom="@+id/btn_start_scan"
android:layout_marginLeft="63dp"
android:layout_toRightOf="@+id/btn_start_scan"
android:text="HIT" />

<Button
android:id="@+id/btn_start_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="42dp"
android:layout_marginLeft="83dp"
android:text="SCAN" />

</RelativeLayout>

有人知道有什么帮助吗?

最佳答案

试一试

 In ZXing:

1. Right click on project
2. Click Properties
3. Click Android in the left hand side menu
4. Check Is Library

In my app:
1. Right click on project
2. Click Properties
3. Click Android in the left hand side menu
4. Click Add
5. Select the ZXing project

关于java - Zxing 库应用程序集成运行时异常 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933443/

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