Can anyone help me implement the java code that works in the Main module. I want to implement it in a class called Print.
But when I try to use it in the Print class, it gives an error in the JAVA code:
error: incompatible types: print cannot be converted to Context
printer = Printer.getInstance(this);
I've tried several ways to run the code in the class, and there's always an error.
But when I try to use it in the Print class, it gives an error in the JAVA code:
error: incompatible types: print cannot be converted to Context
printer = Printer.getInstance(this);
I've tried several ways to run the code in the class, and there's always an error.
Main:
#Region Project Attributes
#ApplicationLabel: maquininhaLite
#VersionCode: 1
#VersionName: 1
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#BridgeLogger: True
#End Region
#AdditionalJar: positivo-printer-1.00.00.aar
#AdditionalJar: posmpapi_1.01.01.aar
Sub Process_Globals
Private xui As XUI
Private NativeMe As JavaObject
Private Print1 As print
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
NativeMe.InitializeContext
End If
Print1.Initialize
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub Activity_Click
'work
imprimirTexto("Teste Activity")
'not work
Print1.imprimirTexto("Teste Class")
End Sub
Public Sub imprimirTexto(Texto1 As String)
NativeMe.RunMethod("imprimirTexto", Array As String(Texto1))
End Sub
'Inline Java Code -> https://www.b4x.com/android/forum/threads/inline-java-code.50141
#IF JAVA
//biblioteca immpressora
import br.com.execucao.posmp_api.printer.Printer;
import br.com.execucao.posmp_api.printer.PrinterListener;
private Printer printer;
public void imprimirTexto(String texto1) {
printer.print(texto1);
}
public void _onCreate() {
printer = Printer.getInstance(this);
printer.open();
printer.setFeedLineAuto(true);
}
public void _onDestroy() {
printer.close();
}
#End If
Class Print:
Private Sub Class_Globals
Private NativeMe As JavaObject
End Sub
Public Sub Initialize
NativeMe.InitializeContext
End Sub
Public Sub imprimirTexto(Texto1 As String)
NativeMe.RunMethod("imprimirTexto", Array As String(Texto1))
End Sub
'Inline Java Code -> https://www.b4x.com/android/forum/threads/inline-java-code.50141
#IF JAVA
//biblioteca immpressora
import br.com.execucao.posmp_api.printer.Printer;
import br.com.execucao.posmp_api.printer.PrinterListener;
private Printer printer;
public void imprimirTexto(String texto1) {
printer.print(texto1);
}
public void _onCreate() {
//printer = Printer.getInstance(this);
printer.open();
printer.setFeedLineAuto(true);
}
public void _onDestroy() {
printer.close();
}
#End If
Erro:
B4A Versão: 12.50
Analisando o código. (0.01s)
Java Versão: 14
Building folders structure. (0.02s)
Compilando o código (0.03s)
Compilando código dos layouts. (0.00s)
Organizando bibliotecas (0.00s)
(AndroidX SDK)
Compilando recursos (0.08s)
Linkando recursos (0.33s)
Compilando o código Java. Error
src\b4a\example\print.java:68: error: incompatible types: print cannot be converted to Context
printer = Printer.getInstance(this);
^
Note: src\b4a\example\main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
javac 14.0.1