Android Question equivalent from java to b4a

rogel a. tolentino

Member
Licensed User
What is the equivalent b4a code for the java code shown below? I'm not familiar with Java. This is a code for barcode printing for bixolon printer
it has a library bixolon_printer_v2.1.4.jar. Please help me

import com.bxl.config.editor.BXLConfigLoader;
import jpos.config.JposEntry;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import com.bxl.BXLConst;
try
{
POSPrinter posPrinter = new POSPrinter(this);
posPrinter.open(“SPP-R200III”);
posPrinter.claim(5000);
posPrinter.setDeviceEnabled(true);
posPrinter.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
“123456789”,
POSPrinterConst.PTR_BCS_QRCODE,
8,
8,
POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_BELOW);
}
catch(JposException e)
{
e.printStackTrace();
}
 

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Try this..

- Check javaobject library
- Copy bixolon_printer_v2.1.4.jar file to additional libraries folder
- In the main module above process_globals add this line:
B4X:
#AdditionalJar: bixolon_printer_v2.1.4.jar
- Add this code in your app:
B4X:
Sub Process_Globals   
    Private NativeMe As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    If FirstTime Then
        NativeMe.InitializeContext
    End If   
End Sub

Sub button1_Click
    NativeMe.RunMethod("printpix", Null)
End Sub

#If Java
import com.bxl.config.editor.BXLConfigLoader;
import jpos.config.JposEntry;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import com.bxl.BXLConst;
public void printpix(){
    try
    {
        POSPrinter posPrinter = new POSPrinter(this);
        posPrinter.open(“SPP-R200III”);
        posPrinter.claim(5000);
        posPrinter.setDeviceEnabled(true);
        posPrinter.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
        “123456789”,
        POSPrinterConst.PTR_BCS_QRCODE,
        8,
        8,
        POSPrinterConst.PTR_BC_CENTER,
        POSPrinterConst.PTR_BC_TEXT_BELOW);
    }
        catch(JposException e)
    {
        e.printStackTrace();
    }
}
#End If
 
Upvote 0

rogel a. tolentino

Member
Licensed User
Sub button1_Click
NativeMe.RunMethod("printpix", Null) 'to change this line to Native.RunMethod("printpix","123456789")
End Sub

#If Java
import com.bxl.config.editor.BXLConfigLoader;
import jpos.config.JposEntry;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import com.bxl.BXLConst;
public void printpix(){ //to change this line to public void printfix(String acct){
try
{
POSPrinter posPrinter = new POSPrinter(this);
posPrinter.open(“SPP-R200III”);
posPrinter.claim(5000);
posPrinter.setDeviceEnabled(true);
posPrinter.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
“123456789”, //to change this line to acct;

Can you help me what is wrong on my proposed changes? (those with remarks to change this line)
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Try:
B4X:
Sub Process_Globals  
    Private NativeMe As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)  
    If FirstTime Then
        NativeMe.InitializeContext
    End If  
End Sub

Sub button1_Click
    NativeMe.RunMethod("printpix", "123456")
End Sub

#If Java
import com.bxl.config.editor.BXLConfigLoader;
import jpos.config.JposEntry;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import com.bxl.BXLConst;
public static void printpix(String acc){
    try
    {
        POSPrinter posPrinter = new POSPrinter(this);
        posPrinter.open(“SPP-R200III”);
        posPrinter.claim(5000);
        posPrinter.setDeviceEnabled(true);
        posPrinter.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
        acc,
        POSPrinterConst.PTR_BCS_QRCODE,
        8,
        8,
        POSPrinterConst.PTR_BC_CENTER,
        POSPrinterConst.PTR_BC_TEXT_BELOW);
    }
        catch(JposException e)
    {
        e.printStackTrace();
    }
}
#End If
 
Upvote 0

rogel a. tolentino

Member
Licensed User
1654042997631.png
 
Upvote 0

teddybear

Well-Known Member
Licensed User
It has told you error:incompatiible types:String cannot be coverted to Object[]
B4X:
Sub button1_Click
     '''NativeMe.RunMethod("printpix", "123456")
    NativeMe.RunMethod("printpix", array("123456")) 'Pass an Object[]

End Sub
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hello Rogel a. tolentino,
I would like to ask for your finished code after you success your app for study. It's interesting for learning B4A's code.

Best regards,
Theera
 
Upvote 0
Top