gpt4 book ai didi

java - : Lcom/abhi/barcode/frag/libv2/R$string 解析失败

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:29 24 4
gpt4 key购买 nike

我正在尝试启动一个带有 Fragment 的 Activity,该 Activity 正在执行 QR 扫描,我正在为此使用这个库 > https://code.google.com/archive/p/barcodefraglibv2/

我按照说明做所有事情,但是当我运行该应用程序时,它会抛出一个异常:

Failed resolution of: Lcom/abhi/barcode/frag/libv2/R$string

我做错了什么?

这是我的主要 Activity :

package apps.radwin.zxingprojectfragmentsthree;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.abhi.barcode.frag.libv2.BarcodeFragment;
import com.abhi.barcode.frag.libv2.IScanResultHandler;
import com.abhi.barcode.frag.libv2.ScanResult;
import com.google.zxing.BarcodeFormat;

import java.util.EnumSet;

public class MainActivity extends FragmentActivity implements IScanResultHandler {

BarcodeFragment fragment;
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragment = (BarcodeFragment)getSupportFragmentManager().findFragmentById(R.id.sample);
fragment.setScanResultHandler(this);
btn = ((Button)findViewById(R.id.scan));
btn.setEnabled(false);

// Support for adding decoding type
fragment.setDecodeFor(EnumSet.of(BarcodeFormat.QR_CODE));
}

@Override
public void scanResult(ScanResult result) {
btn.setEnabled(true);
Toast.makeText(this, result.getRawResult().getText(), Toast.LENGTH_LONG).show();
}

public void scanAgain(View v){
fragment.restart();
}
}

这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "apps.radwin.zxingprojectfragmentsthree"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile files('libs/barcodelib.jar')
compile files('libs/core.jar')
}

我的 Activity XML >

 <?xml version="1.0" encoding="utf-8"?>
<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">

<fragment
android:id="@+id/sample"
android:name="com.abhi.barcode.frag.libv2.BarcodeFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/scan"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<Button
android:id="@+id/scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="scanAgain"
android:text="Re-Scan" />
</RelativeLayout>

我的异常(exception)是:

FATAL EXCEPTION: main

Process: apps.radwin.zxingprojectfragmentsthree, PID: 11692
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/abhi/barcode/frag/libv2/R$string;
at com.abhi.barcode.frag.libv2.BarcodeFragment.displayFrameworkBugMessageAndExit(BarcodeFragment.java:345)
at com.abhi.barcode.frag.libv2.BarcodeFragment.initCamera(BarcodeFragment.java:338)
at com.abhi.barcode.frag.libv2.BarcodeFragment.surfaceCreated(BarcodeFragment.java:212)
at android.view.SurfaceView.updateWindow(SurfaceView.java:712)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:209)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1014)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.abhi.barcode.frag.libv2.R$string" on path: DexPathList[[zip file "/data/app/apps.radwin.zxingprojectfragmentsthree-1/base.apk"],nativeLibraryDirectories=[/data/app/apps.radwin.zxingprojectfragmentsthree-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.abhi.barcode.frag.libv2.BarcodeFragment.displayFrameworkBugMessageAndExit(BarcodeFragment.java:345) 
at com.abhi.barcode.frag.libv2.BarcodeFragment.initCamera(BarcodeFragment.java:338) 
at com.abhi.barcode.frag.libv2.BarcodeFragment.surfaceCreated(BarcodeFragment.java:212) 
at android.view.SurfaceView.updateWindow(SurfaceView.java:712) 
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:209) 
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1014) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920) 
at android.view.Choreographer.doCallbacks(Choreographer.java:695) 
at android.view.Choreographer.doFrame(Choreographer.java:631) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Suppressed: java.lang.ClassNotFoundException: com.abhi.barcode.frag.libv2.R$string
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

在我的 app/libs 文件夹中,我有两个文件,barcodelib.jar 和 code.jar,我在 android studio 中按下 barcodelib.jar 文件右键单击,然后添加为库,我也无法在 core.jar 上按下它,它没有提供选项。

你能帮我说说我做错了什么吗?

最佳答案

从 API 级别 23 开始,需要在运行时请求相机权限

将您的 onCreate 代码更改为:

        if (PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA))
{

// asks primission to use the devices camera
fragment = (BarcodeFragment)getSupportFragmentManager().findFragmentById(R.id.sample);
fragment.setScanResultHandler(this);
btn = ((Button)findViewById(R.id.scan));
btn.setEnabled(false);

// Support for adding decoding type
fragment.setDecodeFor(EnumSet.of(BarcodeFormat.QR_CODE));

}
else
{
requestWritePermission(MainActivity.this);
}

并添加此功能以征求用户的许可:

    private static void requestWritePermission(final Context context) 
{
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, Manifest.permission.CAMERA))
{
new AlertDialog.Builder(context).setMessage("This app needs permission to use The phone Camera in order to activate the Scanner")
.setPositiveButton("Allow", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which)
{ ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA}, 1);}
}).show();
}
else
{
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA}, 1);
}
}

最好在进入 fragment Activity 之前使用它添加这些行并重试。另外,要获得更多输入,请阅读流畅的文章:

https://developer.android.com/training/permissions/requesting.html

关于java - : Lcom/abhi/barcode/frag/libv2/R$string 解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38828934/

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