gpt4 book ai didi

android - 无法使用上述方法连接打印机 Zebra MZ 220

转载 作者:行者123 更新时间:2023-11-30 04:10:02 24 4
gpt4 key购买 nike

我有以下代码可以使用我的 android 2.3.7 在我的 zebra mz 220 中打印:

public class Printing extends Activity {
ProgressDialog dialog;
ZebraPrinterConnection zebraPrinterConnection;
ZebraPrinter zebra;
String mac;

Handler handlerWorking = new Handler(){
@Override
public void handleMessage(Message msg){
String returnedValue = (String)msg.obj;
//textV.setText("Returned by thread Circle:" + returnedValue);
}
};

Handler handlerDone = new Handler(){
@Override
public void handleMessage(Message msg){
String returnedValue = (String)msg.obj;
//textV.setText(returnedValue);
}
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle bundle = this.getIntent().getExtras();
String mac = bundle.getString("param1");
this.mac = mac;

System.out.println(mac);
showDialog(0);
//finish();
}


@Override
public Dialog onCreateDialog(int id){
final Runnable threadMethod = new Runnable() {
public void run(){
try{
connect();
}catch(Throwable e){

}
Message msg = handlerDone.obtainMessage(1, "DONE!!!");
handlerDone.sendMessage(msg);
dialog.dismiss();
}
};

dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Loading...");
Thread thread = new Thread(null, threadMethod, "Thread1");
thread.start();
return dialog;
}

public void connect() {
Looper.prepare();
zebraPrinterConnection = null;
zebraPrinterConnection = new BluetoothPrinterConnection(mac);

try {
zebraPrinterConnection.open();
} catch (ZebraPrinterConnectionException e) {
disconnect();
}

if (zebraPrinterConnection.isConnected()) {
try {
zebra = ZebraPrinterFactory.getInstance(zebraPrinterConnection);
sendLabel();
} catch (ZebraPrinterConnectionException e) {
zebra = null;
disconnect();
} catch (ZebraPrinterLanguageUnknownException e) {
zebra = null;
disconnect();
}
}
Looper.loop();
Looper.myLooper().quit();
}

public void disconnect() {
try {
if (zebraPrinterConnection != null) {
zebraPrinterConnection.close();
}
} catch (ZebraPrinterConnectionException e) {

}
}

private byte[] getLabel() {
PrinterLanguage printerLanguage = zebra.getPrinterControlLanguage();
byte[] configLabel = null;
if (printerLanguage == PrinterLanguage.ZPL) {
configLabel = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ".getBytes();
} else if (printerLanguage == PrinterLanguage.CPCL) {
String cpclConfigLabel = "! 0 200 200 50 1\r\n" + "ON-FEED IGNORE\r\n" + "T 5 0 0 0 Hola\r\n" + "PRINT\r\n";
configLabel = cpclConfigLabel.getBytes();
}
return configLabel;
}

private void sendLabel() {
try {
byte[] configLabel = getLabel();
zebraPrinterConnection.write(configLabel);
} catch (ZebraPrinterConnectionException e) {

} finally {
disconnect();
}
}

问题是我的 logCat 上出现了下一个错误:

06-12 11:08:03.327: E/AndroidRuntime(14323): FATAL EXCEPTION: main
06-12 11:08:03.327: E/AndroidRuntime(14323): java.lang.VerifyError: com.api.printer.zebra.Printing
06-12 11:08:03.327: E/AndroidRuntime(14323): at java.lang.Class.newInstanceImpl(Native Method)
06-12 11:08:03.327: E/AndroidRuntime(14323): at java.lang.Class.newInstance(Class.java:1409)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.os.Looper.loop(Looper.java:130)
06-12 11:08:03.327: E/AndroidRuntime(14323): at android.app.ActivityThread.main(ActivityThread.java:3835)
06-12 11:08:03.327: E/AndroidRuntime(14323): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 11:08:03.327: E/AndroidRuntime(14323): at java.lang.reflect.Method.invoke(Method.java:507)
06-12 11:08:03.327: E/AndroidRuntime(14323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
06-12 11:08:03.327: E/AndroidRuntime(14323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-12 11:08:03.327: E/AndroidRuntime(14323): at dalvik.system.NativeStart.main(Native Method)

如果我评论 disconnect 方法、sendLabel 方法和 getLabel 方法,应用程序不会崩溃,但会出现下一个错误行:

06-12 11:13:35.207: E/dalvikvm(15869): Could not find class 'com.zebra.android.comm.BluetoothPrinterConnection', referenced from method com.api.printer.zebra.Printing.connect

我的引用库中有 zebra(ZSDK_API.jar) 库,这是怎么回事?感谢您的宝贵时间。

最佳答案

根据您使用的 ADT 版本(如果您确实使用 Eclipse),如果您使用的是最新版本,则将 ZSDK_API.jar 放入您的 libs/目录中就足够了。这应该被 Android 构建过程拾取。然后,该 jar 应该会自动显示在您的 Android 项目的 Android 依赖项库中。

查看此 URL 以获取更多信息:http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

关于android - 无法使用上述方法连接打印机 Zebra MZ 220,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11000621/

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