Android 2.3.7を使用してゼブラ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) のライブラリがありますが、何が起こっていますか? 御時間ありがとうございます。