- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,所以我正在为我的公司开发一个内部条形码扫描仪,以便在我们移动计算机和设备时使用。经过一些试验和错误后,我目前几乎通过 Intent 设置了 Zxing 条码扫描仪。
这是我正在尝试做的事情。
在三个 EditText
字段旁边,我有三个 ImageButtons
,单击它们时,实现 BarcodeScanner
,扫描后返回值并输入值进入 EditText
字段。我能够使用一个对应于一个 ImageButton
的“监听器”成功地做到这一点。但是在尝试对一个监听器使用多个 Button
后,它会调用条形码扫描仪,但在尝试返回条形码值时会崩溃。
调试器显示主线程已暂停,我必须在 Logcat 中出现 RuntimeException
错误之前恢复调试器两次。
这是来自 LogCat 的错误日志:
07-17 17:38:49.251: E/AndroidRuntime(30942): java.lang.RuntimeException: Unable to resume activity {com.fmi.inventory/com.fmi.inventory.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }} to activity {com.fmi.inventory/com.fmi.inventory.MainActivity}: java.lang.NullPointerException
这是我的 MainActivity:
package com.fmi.inventory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton button;
ImageButton button1;
ImageButton button2;
EditText editField;
Activity activity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity = this;
button = (ImageButton)findViewById(R.id.scanCubeID);
button1 = (ImageButton)findViewById(R.id.scanEmployeeID);
button2 = (ImageButton)findViewById(R.id.scanConfigID);
button.setOnClickListener(listener);
button1.setOnClickListener(listener);
button2.setOnClickListener(listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onResume() {
super.onResume();
}
public void setCubeClick(){
editField = (EditText)findViewById(R.id.editCubeID);
}
public void setEmployeeClick(){
editField = (EditText)findViewById(R.id.editEmployeeID);
}
public void setConfigClick(){
editField = (EditText)findViewById(R.id.editConfigID);
}
private View.OnClickListener listener = new View.OnClickListener() {
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.initiateScan();
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
case IntentIntegrator.REQUEST_CODE:
if (resultCode == Activity.RESULT_OK) {
IntentResult intentResult = IntentIntegrator
.parseActivityResult(requestCode, resultCode, intent);
if (intentResult != null) {
String contents = intentResult.getContents();
String format = intentResult.getFormatName();
this.editField.setText(contents);
// this.elemQuery.setText(contents);
//this.resume = false;
Log.d("SEARCH_EAN", "OK, EAN: " + contents + ", FORMAT: "
+ format);
} else {
Log.e("SEARCH_EAN", "IntentResult je NULL!");
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.e("SEARCH_EAN", "CANCEL");
}
}
}
}
这是我的 MainActivity 布局 .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" >
<EditText
android:id="@+id/editCubeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/scanEmployeeID"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/scanCubeID"
android:ems="10"
android:hint="@string/edit_cubeid" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editEmployeeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/scanConfigID"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/editCubeID"
android:layout_below="@+id/editCubeID"
android:ems="10"
android:hint="@string/edit_employeeid" />
<EditText
android:id="@+id/editConfigID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/scanConfigID"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/editEmployeeID"
android:layout_below="@+id/editEmployeeID"
android:ems="10"
android:hint="@string/edit_configid" />
<ImageButton
android:id="@+id/scanCubeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/desc"
android:layout_alignParentTop="true"
android:src="@drawable/ic_action_scan"
android:onClick="onClick" />
<ImageButton
android:id="@+id/scanEmployeeID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/desc"
android:layout_below="@+id/scanCubeID"
android:src="@drawable/ic_action_scan"
android:onClick="onClick" />
<ImageButton
android:id="@+id/scanConfigID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/desc"
android:layout_below="@+id/scanEmployeeID"
android:src="@drawable/ic_action_scan"
android:onClick="onClick" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editConfigID"
android:text="@string/button_continue" />
</RelativeLayout>
最佳答案
当你的Activity
扫描后进入onActivityResult
。你正在访问editField
,但它是NULL。
因为你从未初始化它..
您正在 setCubeClick
、setEmployeeClick
或 setConfigClick
中初始化它们,
但我担心他们从未调用过..尝试在OnCreat
中Initialize
他们
关于android - 附加到条形码应用程序中多个按钮的监听器异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11544674/
我有一个正在动态生成的条形码,并希望传递给 gsp,该 gsp 稍后将变成 pdf。我不需要出于自己的任何目的保留条形码,只想将图像从 Controller 传递到 gsp。 有没有办法渲染作为变量传
我正在研究苹果“passkit”框架。我已经制作了 lolipop 优惠券,正如它在 guide 中所说的那样. - 创建证书(Apple Dev 网站)我已经编译了.pkpass。 现在我必须使用动
我有这样的代码 $('.testbarcode').barcode('1234567', "code128"); 当我设置样式时它是折线,那么我如何才能将此条码的宽度设置得
我正在将 Visual Basic 应用程序转换为 Python Django。目前,它具有条形码功能来处理商店的销售。这可以用 python django 实现吗? 最佳答案 如果您对条形码功能的定
我正在尝试按照此示例使用条形码 API https://github.com/googlesamples/android-vision/tree/master/visionSamples/barcod
这是我到目前为止所得到的: def encodeFive(zip): zero = "||:::" one = ":::||" two = "::|:|" t
我正在尝试创建具有本文所示格式的条形码:http://www.thebookdesigner.com/2009/10/self-publishing-basics-deciphering-the-bo
我需要一些关于如何从 bmp 文件中获取 12 位条形码的指导,我完全不知道如何处理这个问题。我首先将图像读入 bitmam,我该如何继续? 例子:下图的条码是081034489030。我如何获得这些
谁能告诉我从哪里开始编码以便从 C# 中的 OPOS(Datalogic Magellan 设备)加权和条形码扫描中获取数据?例如,在这种情况下我应该使用什么库和什么函数。我一无所知,因为我已经花了很
使用 zxing,我设法将 Code39 条形码保存为 PNG,但它只显示条形,没有数字。我怎样才能在一个 PNG 中包含条形码和编号? KI 最佳答案 您无法使用 zxing 添加号码。您可以做一些
我正在尝试将扫描的条形码用作 SQL 查询中的变量。我正在使用 Google ML Kit Quick Start项目。我有一个使用 jtds1.3.1 制作的连接和查询功能。我只是无法获得要在查询中
我尝试让程序从下面的代码中读取 EAN13,但它不起作用 func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metada
我必须读取 PDF 文件中的数据矩阵代码,我正在研究其可能性,对此我有一些疑问: 1.- 我与 Itext 合作,我正在寻找有关使用此库读取此 QR 条形码的可能性的信息,但我没有相关结果,这可能吗?
文档和头文件不包含任何与支持 3D 条形码相关的信息。但是,明确提到 AVMetadataMachineReadableCodeObject 支持一维和二维条码。因此,有人知道 AVFoundatio
我一直在寻找解决方案,到目前为止,我认为对我的项目来说最好的解决方案是使用免费的 Code 39 字体。但是,我已经尝试打印一些样本,但我的条形码扫描仪无法读取它们。 我进行了更多研究,偶然发现了 t
生成 3 of 9 很容易条形码使用 Font() Font f = new Font("Free 3 of 9", 80); this.Font = f; Label l = new Label()
愚蠢的我,我以为只要用条形码字体写一些文本,就会让扫描仪读取它。看来我错了。 所以在阅读了一些关于 code128 条形码的文档之后,我了解到: 条形码以(103、104 或 105 取决于类型)开头
我想在 WPF 应用程序中区分(条形码)扫描仪和键盘输入。 我需要的是每当我的扫描仪提供数据时发生的事件。 在我的应用程序中有一个特殊的字段,它将填充来自扫描仪的输入。因此,如果用户关注其他领域,我不
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
是否可以将 ZPL 和二进制数据用于 aztec 条形码? 我尝试使用BluetoothConnection写入发送以UTF8和字节数据编码的字符串连接数组/ String zplStart; byt
我是一名优秀的程序员,十分优秀!