Android Question Exception using JavaObject and AdditionalJar SDK

Glpm_2017

Member
Licensed User
Hello, I'be been trying to use the JavaObject to access a Java API for a rfid reader sdk.
The fist code I tried is below :

B4X:
#Region  Project Attributes
   #ApplicationLabel: Test RFID
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

#AdditionalJar: DeviceAPIver20150929

Sub Process_Globals
   Dim mReader As JavaObject
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)

       mReader.InitializeStatic("com.rscja.deviceapi.RFIDWithUHF")
       mReader.RunMethod("init",Null)   
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

When running this code, the following exception occurs :

java.lang.IllegalArgumentException: expected receiver of type com.rscja.deviceapi.RFIDWithUHF, but got java.lang.Class<com.rscja.deviceapi.RFIDWithUHF>

in the line
mReader.RunMethod("init",Null)

Next, I tried to use the following :

B4X:
Sub Activity_Create(FirstTime As Boolean)
       Dim F As Boolean
       mReader.InitializeNewInstance("com.rscja.deviceapi.RFIDWithUHF",Null)
       F =mReader.RunMethod("init",Null)

End Sub

which throws me the error :

java.lang.IllegalAccessException: access to constructor not allowed

I have just a basic knowledge of Java, not enough to determine the cause of the errors...

Could someone please give me some advice on this issue ?

Thanks in advance for your kind assistance.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Glpm_2017

Member
Licensed User
Just to be sure, I downloaded again the files from your Dropbox, but the error is the same, using tha last versions of the libs and the sample program.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Just to be sure, I downloaded again the files from your Dropbox, but the error is the same, using tha last versions of the libs and the sample program.
My fault... I did not removed the call to the Background-task like i wanted..

Download v0.13 please and try again.
 
Upvote 0

Glpm_2017

Member
Licensed User
It's ok now, running without errors.
However, any method or function I try to run after initReader gives me an error :

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 339)
java.lang.NoClassDefFoundError: com/rscja/deviceapi/DeviceAPI
   at com.rscja.deviceapi.RFIDWithUHF.getDeviceAPI(SourceFile:34)
   at com.rscja.deviceapi.RFIDWithUHF.getFrequencyMode(SourceFile:379)
   at de.donmanfred.RFIDWithUHFwrapper.getFrequencyMode(RFIDWithUHFwrapper.java:95)
   at b4a.example.main._activity_create(main.java:339)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
   at b4a.example.main.afterFirstLayout(main.java:102)
   at b4a.example.main.access$000(main.java:17)
   at b4a.example.main$WaitForLayout.run(main.java:80)
   at android.os.Handler.handleCallback(Handler.java:808)
   at android.os.Handler.dispatchMessage(Handler.java:103)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:5292)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
   at dalvik.system.NativeStart.main(Native Method)
It seems that some class is missing.
Other thing, the function UHF_Init is supposed to fire when initialization is finished ? When I ran the program there is no message shown in the log regarding do this function.
Anyway, I think we are closer to the solution now.
Best Regards,
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
after initReader gives me an error
did the uhf_init event raise??
I expect the reader will raise this event when it is ready.
Other thing, the function UHF_Init is supposed to fire when initialization is finished ?
yes

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim uhf As RFIDWithUHF
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    uhf.Initialize("UHF")
    uhf.initReader 'This method should raise the UHF_Init event after it finishes.
End Sub
Sub UHF_Init(success As Boolean)
    Log($"UHF_Init(${success})"$)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Tried again, with no success. The UHF_Init event does not fire. and no message in the log.
hmmm... No error but also no Event.. I´m a bit lost now.
Hard to do a wrap for something if i do not have such a Module to test.

You can try to enable the unfiltered log and check if you get some infos there...
 
Upvote 0

Glpm_2017

Member
Licensed User
Ok, don't worry.. I can imagine how difficult it must be without having the equipment.
I followed your advice and run the program with unfiltered log. After some time collecting the info, I tried to check whether there was something strange. I've found the exceptions below :

** Activity (main) Resume **
Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/rscja/deviceapi/DeviceAPI;


java.lang.SecurityException: Neither user 10003 nor current process has android.permission.PACKAGE_USAGE_STATS.
at android.app.ContextImpl.enforce(ContextImpl.java:1780)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1809)
at com.android.server.am.UsageStatsService.getAllPkgUsageStats(UsageStatsService.java:862)
at com.android.internal.app.IUsageStats$Stub.onTransact(IUsageStats.java:113)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
Could not fetch usage stats


Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
java.lang.NullPointerException
at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
No known package when getting name for resource number 0x9c030103
No known package when getting name for resource number 0x9c030103
[DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x64608db8
No known package when getting name for resource number 0x9c030203
No known package when getting name for resource number 0x9c030203
No known package when getting name for resource number 0x9b000000
No known package when getting name for resource number 0x9b010100
No known package when getting name for resource number 0x9b030300
Skip composition for [Built-in Screen (type:0)] since dirtyRegion is empty
No known package when getting name for resource number 0x9b040400

If you need the complete log, please let me know.
Regards,
 
Upvote 0

Glpm_2017

Member
Licensed User
Just to check, I stopped the program and inspected the UHF object.
The picture in annex shows that the uhf is exposing some info of the reader (uhf.reader.config). These data are read directly from the equipment. So at least in part the program is communicating with the reader..
 

Attachments

  • 10-03-2018 21-52-27.jpg
    10-03-2018 21-52-27.jpg
    17.4 KB · Views: 307
Upvote 0

Glpm_2017

Member
Licensed User
Changed the manifest file as you requested, but still not getting the init event to work.
The log now shows only one exception :

Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/rscja/deviceapi/DeviceAPI;
 
Upvote 0
Top