实际上,我正在尝试将zebra EMDK库实现到我现有的项目中。 我已逐步遵循以下guide,并且在一个新项目中都能正常工作,但是当我尝试在项目中使用该库时,出现以下错误:
2019-03-13 15:24:55.720 4671-4678/it.gabtamagnini.realco E/art: Failed sending reply to debugger: Broken pipe
2019-03-13 15:25:01.239 4671-4671/it.gabtamagnini.realco E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.gabtamagnini.realco, PID: 4671
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.gabtamagnini.realco/it.gabtamagnini.realco.InventarioActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contentEquals(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contentEquals(java.lang.CharSequence)' on a null object reference
at it.gabtamagnini.realco.InventarioActivity.handleDecodeData(InventarioActivity.java:1160)
at it.gabtamagnini.realco.InventarioActivity.onCreate(InventarioActivity.java:129)
at android.app.Activity.performCreate(Activity.java:6723)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
我得到空指针的代码:
private void handleDecodeData(Intent i) {
//Check the intent action is for us
if (i.getAction().contentEquals("com.symbol.emdksample.RECVR")) {
//Get the source of the data
String source = i.getStringExtra("com.motorolasolutions.emdk.datawedge.source");
//Check if the data has come from the Barcode scanner
if (source.equalsIgnoreCase("scanner")) {
//Get the data from the intent
String data = i.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string");
//Check that we have received data
if(data != null && data.length() > 0)
{
Toast.makeText(InventarioActivity.this,data,Toast.LENGTH_LONG).show();
}
}
}
}
答案 0 :(得分:1)
该教程非常古老-最近不推荐使用Data Capture Profiles。如果您在较新的设备上尝试此操作,那么我怀疑com.motorolasolutions ...的意图已经删除,因为多余的字符串已经是'com.symbol.datawedge.data_string了一段时间。我建议阅读https://developer.zebra.com/community/home/blog/2018/06/03/moving-from-the-emdk-data-capture-profile-to-datawedge,它解释了Data Capture配置文件发生了什么,但是如果您正在寻找一个已知的工作样本,那么http://www.darryncampbell.co.uk/2017/12/13/tutorial-scan-with-datawedge-intent-output-on-zebra-devices/应该是一个很好的起点。
为清楚起见,我为Zebra工作