KimHJ 3 Posted November 8 I create a JavaInterface file using java2op, but I have problems when I use it. I have attached the JavaInterface.pas I get this error when it execute printText. First chance exception at $8689BB93. Exception class EJNIFatal with message 'Java type recieptservice/com/recieptservice/PrinterInterface could not be found'. Process ComcaH10.apk (6409) What is missing? Tanks for any help. uses JavaInterfaces; procedure TMainForm.PrintThis; var Myprinter: JPrinterInterface; begin MyPrinter := TJPrinterInterface.Create; MyPrinter.printText(StringToJString('This Is A Test')); MyPrinter.endWork; end; JavaInterfaces.pas Share this post Link to post
Dave Nottage 557 Posted November 8 1 minute ago, KimHJ said: Exception class EJNIFatal with message 'Java type recieptservice/com/recieptservice/PrinterInterface could not be found' That usually means you have not added the required .jar file (the one you ran Java2OP on) to the project. In Project Manager: Expand the Android 32-bit target Right-click on Libraries Click Add.. Select the .jar file Click OK Note that the .jar will be compiled in regardless of whether you compile for 32-bit or 64-bit. Share this post Link to post
KimHJ 3 Posted November 8 (edited) You are right, I didn't know I had to include the jar file. I have a aidl and a jar, I made the JavaInterface.pas from the aidl, do I need to add that as well? Thanks. Edited November 8 by KimHJ Share this post Link to post
KimHJ 3 Posted November 16 I added the jar file, I did not see anything about adding the aidl in Embarcadero's website about jar files. Now I get an exception class 6 in Andoidapi.JNIBridge in class procedure TBridgeHelper.Alloc Could this be because I used the aidl file to create the JavaInterfaces.pas? Share this post Link to post
Dave Nottage 557 Posted November 16 1 hour ago, KimHJ said: I did not see anything about adding the aidl in Embarcadero's website about jar files. That's because you don't need to. 1 hour ago, KimHJ said: Could this be because I used the aidl file to create the JavaInterfaces.pas? Possibly - the Java signatures in that file look a bit odd. Is the .jar file available publicly? Share this post Link to post
KimHJ 3 Posted November 17 Yes, I will create a new java2op using the jar. Share this post Link to post
KimHJ 3 Posted Monday at 10:59 PM Now I get exception 6 in the create line. Do I call the wrong class? procedure TMainForm.PrintThis(MyPrint:String); var Myprinter: JPrinterInterface; begin MyPrinter := TJPrinterInterface.Create; MyPrinter.beginWork; MyPrinter.printText(StringToJString('This Is A Test')); MyPrinter.endWork; end; JavaInterfaces.pas Share this post Link to post
Dave Nottage 557 Posted Monday at 11:05 PM 2 minutes ago, KimHJ said: Now I get exception 6 in the create line. Do I call the wrong class? Possibly, but it's hard to tell without access to the .jar. You have not answered this: On 11/16/2024 at 3:33 PM, Dave Nottage said: Is the .jar file available publicly? If it is public, where can it be obtained from? Share this post Link to post
Dave Nottage 557 Posted Monday at 11:17 PM 6 minutes ago, KimHJ said: I have attached it here. Thanks. It appears you should use TJPrinterInterface_Default, rather than TJPrinterInterface. Share this post Link to post
KimHJ 3 Posted Tuesday at 01:13 AM Thanks, It worked I don't get any errors. Now I just have to find out why it's not printing. When I look at the Android example code it looks like they jus send the command printText MainActivity.this.findViewById(R.id.test2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { SrPrinter.getInstance(getApplicationContext()).printText(((EditText) findViewById(R.id.test1)).getText().toString()); } catch (Exception e) { e.printStackTrace(); } } }); Here are the the first part of the SrPrinter.class package com.sr; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Bitmap; import android.os.IBinder; import android.os.RemoteException; import java.util.Deque; import java.util.concurrent.LinkedBlockingDeque; import recieptservice.com.recieptservice.PSAMCallback; import recieptservice.com.recieptservice.PrinterInterface; import recieptservice.com.recieptservice.PrinterInterface.Stub; public class SrPrinter { static SrPrinter srPrinter; static Deque<Runnable> deque; static volatile PrinterInterface printerInterface = null; static boolean reconnect = false; static ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName componentName, IBinder iBinder) { SrPrinter.printerInterface = Stub.asInterface(iBinder); synchronized(SrPrinter.deque) { while(SrPrinter.printerInterface != null && !SrPrinter.deque.isEmpty()) { ((Runnable)SrPrinter.deque.poll()).run(); } } } public void onServiceDisconnected(ComponentName componentName) { SrPrinter.printerInterface = null; SrPrinter.reconnect = true; } }; public SrPrinter() { } public static synchronized SrPrinter getInstance(Context context) { Intent intent; if (srPrinter != null) { if (reconnect) { intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); reconnect = false; } return srPrinter; } else { srPrinter = new SrPrinter(); deque = new LinkedBlockingDeque(); intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); return srPrinter; } } Share this post Link to post
Dave Nottage 557 Posted Tuesday at 01:27 AM 9 minutes ago, KimHJ said: intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); I do not see the recieptservice.com.recieptservice.service.PrinterService class anywhere in the .jar file you attached. Did you compile the .jar yourself? 12 minutes ago, KimHJ said: When I look at the Android example code.. Where is this example code? Share this post Link to post
KimHJ 3 Posted Tuesday at 04:49 PM No, that is the jar file they emailed me in the SDK, with the example. I just posted a bit of the sample, here is the SDK I was emailed. The SDK is 18mb here is my dropbox link. https://www.dropbox.com/scl/fi/0nw4mhyha0qx72m4dbgfn/Java-Printer-SDK.zip?rlkey=tcn49jv2vt4ofmg90xojnzun5&dl=0 Share this post Link to post
Dave Nottage 557 Posted Tuesday at 08:35 PM (edited) 3 hours ago, KimHJ said: The SDK is 18mb here is my dropbox link. The file printer.jar in the SDK appears to be a cut-down version (not sure why they provide it in the first place - it might be in error) of the one you actually need to use, which is inside printer-release.aar. If you have Delphi 12.2, you can add this file to the Libraries node under Android 32-bit target in Project Manager instead of printer.jar. This library includes the required methods of SrPrinter (e.g. getInstance), so you should be able to use this function to get an instance of it: uses Androidapi.Helpers; function SrPrinter: JSrPrinter; begin Result := TJSrPrinter.JavaClass.getInstance(TAndroidHelper.Context); end; ..and call the functions like they do in the Java examples, e.g.: SrPrinter.printQRCode(StringToJString('123456'), 4, 3); However you will need to first: Rename printer-release.aar to printer-release.zip Extract the classes.jar file from the .zip file Run Java2OP on the extracted classes.jar to recreate your JavaInterfaces.pas import. Edited Tuesday at 08:35 PM by Dave Nottage 1 Share this post Link to post
KimHJ 3 Posted Tuesday at 09:54 PM Thanks a lot for your help, I would never had been able to find out this by my self. I was almost going back to Android Studio and make the app there. Share this post Link to post
KimHJ 3 Posted Wednesday at 11:16 PM Sorry, I still have problems when compiling the new JavaInterfaces.pas I get those errors all the way down from JSrPrinter_10 [JavaSignature('com/sr/SrPrinter$10')] JSrPrinter_10 = interface(JRunnable) ['{A13C6C9C-B945-4438-A33F-1B4453FD0555}'] function _Getval$line: Integer; cdecl; //function needs result type. With a red line under the $ sign procedure run; cdecl; property val$line: Integer read _Getval$line; // property 'val' does not exsist in base class. With a red line under val($line), read and $ sign in Getval$text end; TJSrPrinter_10 = class(TJavaGenericImport<JSrPrinter_10Class, JSrPrinter_10>) end; Does it looks like Java2Op created some wrong classes? Is it something i can correct manually? Again, thanks for any help. JavaInterfaces.pas Share this post Link to post
Dave Nottage 557 Posted Wednesday at 11:33 PM 11 minutes ago, KimHJ said: Does it looks like Java2Op created some wrong classes? Is it something i can correct manually? Yes - you can safely remove any declarations that have a signature that ends with $ and a number (and remove the corresponding xxxClass declarations), as these are anonymous inner classes. 1 Share this post Link to post
Dave Nottage 557 Posted Thursday at 02:22 AM 6 minutes ago, KimHJ said: Great, that did it. Good to hear, but does that mean it now compiles, or that your app is working also? 🙂 Share this post Link to post
KimHJ 3 Posted Thursday at 02:33 AM Yes, it compiles and it prints. First It didn't print, but then I added the command Nextline(1) first and PrintText after then it printed. Now I just need to create the rest of the app. I'm working on two different apps at the same time as you can see on my posts, not getting enough sleep lately. Again, thanks for all your help. 1 Share this post Link to post