Java Question Problem Creating B4A Library

Reinaldo

Member
Licensed User
Longtime User
Hello, i need print to Zebra printer using the Zebra SDK, i do a little app in eclipse and i can print without problems, but when i made the java class to generate B4A library and use into b4a app, the Zebra methods are not operating and it show error.
I put the class code and the error showed in B4a, when i try to use Imprimir() method.

Class code:

B4X:
package anywheresoftware.b4a.spsoft;

import com.zebra.android.comm.*;




import android.widget.Toast;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA.ShortName;


@ShortName("Zprint")
@Version(1.0f)
@Permissions(values={"android.permission.BLUETOOTH","android.permission.BLUETOOTH_ADMIN"})
public class Zprint {
    /*
     * Interface for zebra print
     */
    public String macaddress;
    public ZebraPrinterConnection zebraPrinterConnection;
   
   
    public void InitZ (String MACADD){
             
        this.macaddress=MACADD;
        Toast.makeText(BA.applicationContext, this.macaddress, Toast.LENGTH_SHORT).show();
    }
   
    public void Imprimir (BA ba){  
        /*
         * Print CPCL code
         */
       
        String cadena1 = "! 0 200 200 210 1\r\n" + "BARCODE 128 1 1 50 150 10 HORIZ\r\n" + "TEXT 7 0 210 60 HORIZ\r\n" + "VBARCODE 128 1 1 50 10 200 VERT\r\n" + "VTEXT 7 0 60 140 VERT\r\n" + "FORM\r\n" + "PRINT\r\n";
       
        zebraPrinterConnection = new BluetoothPrinterConnection(macaddress);
         byte[] configLabel = null;
         configLabel = cadena1.getBytes();
       
        
        try {
            zebraPrinterConnection.open();
             zebraPrinterConnection.write(configLabel);
            disconnect();
            } catch (Exception e ) {
                disconnect();
            }
        }
   
   
    public void disconnect() {
        try {
           
            if (zebraPrinterConnection != null) {
                zebraPrinterConnection.close();
            }
        } catch (Exception e) {
           
            try {
                zebraPrinterConnection.close();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
           
        }
       
    }
   

}

when try to use Imprimir method, show this:
java.lang.NoClassDefFoundError: com.zebra.android.comm.BluetoothPrinterConnection
at anywheresoftware.b4a.spsoft.Zprint.Imprimir(Zprint.java:39)
at b4a.example.main._btnprint_click(main.java:318)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)


at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Thanks for your help.
 
Top