Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到Android Google Play Service Vision条形码扫描仪库_Java_Android_Google Play Services_Google Vision_Android Vision - Fatal编程技术网

Java 未找到Android Google Play Service Vision条形码扫描仪库

Java 未找到Android Google Play Service Vision条形码扫描仪库,java,android,google-play-services,google-vision,android-vision,Java,Android,Google Play Services,Google Vision,Android Vision,我使用Google play services可视API读取条形码。我尝试了一个在某些设备上不起作用的代码。以下是Logcat消息: I/Vision﹕ Supported ABIS: [armeabi-v7a, armeabi] D/Vision﹕ Library not found: /data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopp

我使用Google play services可视API读取条形码。我尝试了一个在某些设备上不起作用的代码。以下是Logcat消息:

I/Vision﹕ Supported ABIS: [armeabi-v7a, armeabi]
D/Vision﹕ Library not found: /data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopper.so
I/Vision﹕ Requesting barcode detector download.
D/AndroidRuntime﹕ Shutting down VM
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: PID: 24921
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
        at android.util.SparseArray.valueAt(SparseArray.java:273)
        at MainActivity$1.onClick(MainActivity.java:50)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
问题是因为设备找不到库
/data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopper.so
,然后我得到了异常,因为设备没有检测到条形码(条形码列表为空)

以下是代码:

    BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext()).build();
    Bitmap bitmap = ((BitmapDrawable) mBarcodeImageView.getDrawable()).getBitmap();
    Frame frame = new Frame.Builder().setBitmap(bitmap).build();
    SparseArray<Barcode> barcodes = detector.detect(frame);

    Barcode thisCode = barcodes.valueAt(0);
    TextView txtView = (TextView) findViewById(R.id.txtContent);
    txtView.setText(thisCode.rawValue);
BarcodeDetector=new BarcodeDetector.Builder(getApplicationContext()).build();
位图位图=((BitmapDrawable)mBarcodeImageView.getDrawable()).getBitmap();
Frame Frame=new Frame.Builder().setbit映射(位图).build();
SparseArray条码=检测器。检测(帧);
条形码thisCode=条形码。值位于(0);
TextView txtView=(TextView)findViewById(R.id.txtContent);
setText(thisCode.rawValue);
Google Play服务在所有设备上都会更新


有人能帮我吗?如何修复它?

我知道已经很晚了,但是有人可能会发现错误,并且仍然觉得这些信息很有用

您的应用程序正在崩溃,原因是
ArrayIndexOutOfBoundsException
。原因如下:

SparseArray条形码=检测器。检测(帧)将所有检测到的
数据
存储在
条形码
数组中。当找不到数据时,它将创建一个空白数组,您将尝试从空白数组中获取索引
0
处的值

在尝试检索数据之前,应该首先检查数组的大小。将代码更改为以下内容:

int totalCodes = barcodes.size();
if (totalCodes > 0) {
    Barcode thisCode = barcodes.valueAt(0);
    TextView txtView = (TextView) findViewById(R.id.txtContent);
    txtView.setText(thisCode.rawValue);
}

或者,您应该使用循环来获取
条形码
数组中的所有元素。

检测
方法返回一个
SparseArray
,它只包含值的键,您应该像这样迭代结果:

for (int i = 0; i < barcodes.size(); i++) {
    Barcode barcode = barcodes.get(barcodes.keyAt(i));
    String value = barcode.displayValue
}
for(int i=0;i
由于
main activity.java:50
上的
ArrayIndexOutOfBoundsException
而导致应用程序崩溃,这与Google Play服务无关。这句话是什么?@ianhanniballake,我刚刚在下面添加了谷歌示例代码。我提到条形码列表是空的,这就是例外的原因。但条形码列表是空的,因为
检测器
无法识别条形码,这才是真正的问题。这是因为设备找不到我上面提到的库。请看我的答案:@JaredBurrows thx!我解决了这个问题。实际上,我需要清除缓存,释放一些空间并重新安装应用程序。