简体   繁体   English

无法使用方法连接打印机Zebra MZ 220

[英]Can not use the methods to connect printer Zebra MZ 220

I have the following code to print in my zebra mz 220 using my android 2.3.7: 我有以下代码使用我的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();
    }
}

The problem is that i get the next errors on my logCat: 问题是我在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)

If i comment the disconnect method, the sendLabel method and the getLabel method the application does not crash but the next error line appears: 如果我注释了断开连接方法,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

I have the library of zebra(ZSDK_API.jar) in my referenced libraries, what is happenning? 我引用的库中有zebra库(ZSDK_API.jar),这是怎么回事? Thanks for your time. 谢谢你的时间。

Depending on the version of ADT you are using (if you are indeed using Eclipse), if you are using the latest version it should be sufficient to put the ZSDK_API.jar in your libs/ directory. 根据所使用的ADT的版本(如果确实使用Eclipse),如果使用的是最新版本,则将ZSDK_API.jar放在libs /目录中就足够了。 This should get picked up by the Android build process. 这应该在Android构建过程中掌握。 The jar should then show up in the Android Dependencies library in your Android project automatically. 然后,该jar应自动显示在Android项目的Android Dependencies库中。

Check this URL for more info: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17 检查此URL以获取更多信息: http : //android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM