Help with reflection!

Kevin

Well-Known Member
Licensed User
I'm trying to access an API (available only on select phones) and I think it can be done with reflection but I'm not too familiar with it and haven't had any success yet. Any reflection gurus out there?

I was made to sign an NDA to get information on this API so I am going to change some details to avoid potential legal troubles. If I am missing anything important, please let me know. :D

I tried the following but receive runtime errors. For now I am just trying to use the transmitIRCmd (or transmitIR) method to send an IR command, and would be nice to get the result back. Eventually I'd also like to use the learn method as well. I am trying to simulate the abcIrData constructor using my own type (ABCData) but I don't even know if that will work. Unfortunately this stuff is way over my head. :confused:

Although it isn't shown in the code, ABCDat gets declared as Type ABCData and the proper values are assigned as necessary.

B4X:
Type ABCData (rc As Int, freq As Int, irframe() As Int) ' irframe should be int array

      'Send command using built-in IR port
      Dim r As Reflector, xCount As Int
      r.Target = r.CreateObject("com.abc.circontrol.CIRControl")
      'r.Target = r.CreateObject("com.abc.htcircontrol.abcIrInterface")

      For xCount = 1 To RepeatCount
         r.RunMethod3 ("transmitIRCmd", ABCDat, "java.lang.object", "False", "java.lang.boolean")
         'r.RunMethod2 ("transmitIR", ABCDat, "java.lang.object")
      Next
      Catch
         Log (LastException)
         ToastMessageShow ("Failed to send IR command.  Is your device supported?", True)
   End Try


The API docs:

com.abc.circontrol
Class CIRControl

java.lang.Object
com.abc.circontrol.CIRControl
public class CIRControl

extends java.lang.Object
CIRControl


Field Summary
static int ERR_CANCEL
The argument 1 of message as result of request, IR activity is canncelled
static int ERR_CANCEL_FAIL
The argument 1 of message as result of request, fail to cancel assigned request
static int ERR_CHECKSUM_ERROR
The argument 1 of message as result of request, checksum error in IR command
static int ERR_CMD_DROPPED
The argument 1 of message as result of request, the request is dropped (if it is droppable)
static int ERR_CMD_FAILED
The argument 1 of message as result of request, failed to carry out request
static int ERR_HW_BUSY
The argument 1 of message as result of request, hardware is busy
static int ERR_INVALID_VALUE
The argument 1 of message as result of request, command arguments or data is invalid
static int ERR_IO_ERROR
The argument 1 of message as result of request, an IO error occured
static int ERR_LEARNING_TIMEOUT
The argument 1 of message as result of request, the learning process expired
static int ERR_NONE
The argument 1 of message as result of request, no error occured
static int ERR_OBJ_ERROR
The argument 1 of message as result of request, object error in JNI native functions
static int ERR_OUT_OF_FREQ
The argument 1 of message as result of request, learning IR frequency is not supported
static int ERR_PIPE_ERROR
The argument 1 of message as result of request, fail to create/read/write pipe
static int ERR_PULSE_ERROR
The argument 1 of message as result of request, pulse data of IR frame is error
static int ERR_TTY_READ_ERROR
The argument 1 of message as result of request, fail to read IR hardware
static int ERR_TTY_SETUP_ERROR
The argument 1 of message as result of request, fail to init IR hardware
static int ERR_TTY_WRITE_ERROR
The argument 1 of message as result of request, fail to write IR hardware
static int ERR_UNKNOWN
The argument 1 of message as result of request, an unknown error occured
static java.lang.String KEY_CMD_RESULT
The key to put/retrieve data the learnt command to/from bundle
static java.lang.String KEY_COMMAND
The key to put/retrieve the command data to/from bundle
static java.lang.String KEY_DISCARD_ID
The key to put/retrieve the target UUID of a request to discard
static java.lang.String KEY_DROPPABLE
The key to put/retrieve the boolean flag to indicate a request is can be dropped or not
static java.lang.String KEY_RESULT_ID
The key to put/retrieve the generated UUID for a request to/from bundle
static java.lang.String KEY_TIMEOUT
The key to put/retrieve the timeout value for learning
static int MSG_ARG_DROPPABLE
An argument flag to indicate the request can be dropped if CIR module is busy
static int MSG_ARG_NORMAL
An argument flag to indicate the request can be queued and cannot be dropped
static int MSG_CMD_CANCEL
A message type for canceling previous request
static int MSG_CMD_DISCARD
A message type for discard specific request
static int MSG_CMD_GET_FW_VER
A message type for retrieving firmware version of CIR module
static int MSG_CMD_LEARN_IR
A message type for learning request
static int MSG_CMD_REGISTER_CLIENT
A message type for registration of a client
static int MSG_CMD_RESET
A message type for resetting CIR module
static int MSG_CMD_TRANSMIT_IR
A message type for generating IR signals
static int MSG_CMD_UNREGISTER_CLIENT
A message type for unregistration of a client
static int MSG_RET_CANCEL
A message type for the result of canceling of a previous request
static int MSG_RET_DISCARD
A message type for the result of discard request
static int MSG_RET_GET_FW_VER
A message type for the result of retrieving firmware version of CIR module
static int MSG_RET_LEARN_IR
A message type for the result of a learning request
static int MSG_RET_RESET
A message type for the result of retset request
static int MSG_RET_STARTED
A message type for the result whether control ready or not
static int MSG_RET_TRANSMIT_IR
A message type for the result of generating a IR signals

Constructor Summary
CIRControl(Context context, Handler handler)
the CIRControl constructor


Method Summary
java.util.UUID cancelCommand()
cancel the on-going command
java.util.UUID discardCommand(java.util.UUID uuid)
discard the specific commands in queue
java.util.UUID getFirmwareVersion()
get the firmware version of CIR module
boolean isStarted()
check if service has been already started successfully
java.util.UUID learnIRCmd(int timeout)
enter learning mode to learn IR signals as a command
java.util.UUID reset()
reset the hardware of CIR module
void start()
bind to CIRModule service
void stop()
unbind to CIRModule service
java.util.UUID transmitIRCmd(abcIrData irData, boolean droppable)
generate IR signals according to information in the abcIrData


Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Field Detail
MSG_CMD_REGISTER_CLIENT

public static final int MSG_CMD_REGISTER_CLIENT
A message type for registration of a client
See Also:
Constant Field Values
MSG_CMD_UNREGISTER_CLIENT

public static final int MSG_CMD_UNREGISTER_CLIENT
A message type for unregistration of a client
See Also:
Constant Field Values
MSG_CMD_LEARN_IR

public static final int MSG_CMD_LEARN_IR
A message type for learning request
See Also:
Constant Field Values
MSG_CMD_TRANSMIT_IR

public static final int MSG_CMD_TRANSMIT_IR
A message type for generating IR signals
See Also:
Constant Field Values
MSG_CMD_GET_FW_VER

public static final int MSG_CMD_GET_FW_VER
A message type for retrieving firmware version of CIR module
See Also:
Constant Field Values
MSG_CMD_RESET

public static final int MSG_CMD_RESET
A message type for resetting CIR module
See Also:
Constant Field Values
MSG_CMD_CANCEL

public static final int MSG_CMD_CANCEL
A message type for canceling previous request
See Also:
Constant Field Values
MSG_CMD_DISCARD

public static final int MSG_CMD_DISCARD
A message type for discard specific request
See Also:
Constant Field Values
MSG_RET_LEARN_IR

public static final int MSG_RET_LEARN_IR
A message type for the result of a learning request
See Also:
Constant Field Values
MSG_RET_TRANSMIT_IR

public static final int MSG_RET_TRANSMIT_IR
A message type for the result of generating a IR signals
See Also:
Constant Field Values
MSG_RET_GET_FW_VER

public static final int MSG_RET_GET_FW_VER
A message type for the result of retrieving firmware version of CIR module
See Also:
Constant Field Values
MSG_RET_RESET

public static final int MSG_RET_RESET
A message type for the result of retset request
See Also:
Constant Field Values
MSG_RET_CANCEL

public static final int MSG_RET_CANCEL
A message type for the result of canceling of a previous request
See Also:
Constant Field Values
MSG_RET_DISCARD

public static final int MSG_RET_DISCARD
A message type for the result of discard request
See Also:
Constant Field Values
MSG_RET_STARTED

public static final int MSG_RET_STARTED
A message type for the result whether control ready or not
See Also:
Constant Field Values
MSG_ARG_NORMAL

public static final int MSG_ARG_NORMAL
An argument flag to indicate the request can be queued and cannot be dropped
See Also:
Constant Field Values
MSG_ARG_DROPPABLE

public static final int MSG_ARG_DROPPABLE
An argument flag to indicate the request can be dropped if CIR module is busy
See Also:
Constant Field Values
ERR_NONE

public static final int ERR_NONE
The argument 1 of message as result of request, no error occured
See Also:
Constant Field Values
ERR_UNKNOWN

public static final int ERR_UNKNOWN
The argument 1 of message as result of request, an unknown error occured
See Also:
Constant Field Values
ERR_CMD_FAILED

public static final int ERR_CMD_FAILED
The argument 1 of message as result of request, failed to carry out request
See Also:
Constant Field Values
ERR_HW_BUSY

public static final int ERR_HW_BUSY
The argument 1 of message as result of request, hardware is busy
See Also:
Constant Field Values
ERR_IO_ERROR

public static final int ERR_IO_ERROR
The argument 1 of message as result of request, an IO error occured
See Also:
Constant Field Values
ERR_CMD_DROPPED

public static final int ERR_CMD_DROPPED
The argument 1 of message as result of request, the request is dropped (if it is droppable)
See Also:
Constant Field Values
ERR_TTY_SETUP_ERROR

public static final int ERR_TTY_SETUP_ERROR
The argument 1 of message as result of request, fail to init IR hardware
See Also:
Constant Field Values
ERR_TTY_WRITE_ERROR

public static final int ERR_TTY_WRITE_ERROR
The argument 1 of message as result of request, fail to write IR hardware
See Also:
Constant Field Values
ERR_TTY_READ_ERROR

public static final int ERR_TTY_READ_ERROR
The argument 1 of message as result of request, fail to read IR hardware
See Also:
Constant Field Values
ERR_INVALID_VALUE

public static final int ERR_INVALID_VALUE
The argument 1 of message as result of request, command arguments or data is invalid
See Also:
Constant Field Values
ERR_LEARNING_TIMEOUT

public static final int ERR_LEARNING_TIMEOUT
The argument 1 of message as result of request, the learning process expired
See Also:
Constant Field Values
ERR_CANCEL_FAIL

public static final int ERR_CANCEL_FAIL
The argument 1 of message as result of request, fail to cancel assigned request
See Also:
Constant Field Values
ERR_CHECKSUM_ERROR

public static final int ERR_CHECKSUM_ERROR
The argument 1 of message as result of request, checksum error in IR command
See Also:
Constant Field Values
ERR_OUT_OF_FREQ

public static final int ERR_OUT_OF_FREQ
The argument 1 of message as result of request, learning IR frequency is not supported
See Also:
Constant Field Values
ERR_CANCEL

public static final int ERR_CANCEL
The argument 1 of message as result of request, IR activity is canncelled
See Also:
Constant Field Values
ERR_PULSE_ERROR

public static final int ERR_PULSE_ERROR
The argument 1 of message as result of request, pulse data of IR frame is error
See Also:
Constant Field Values
ERR_PIPE_ERROR

public static final int ERR_PIPE_ERROR
The argument 1 of message as result of request, fail to create/read/write pipe
See Also:
Constant Field Values
ERR_OBJ_ERROR

public static final int ERR_OBJ_ERROR
The argument 1 of message as result of request, object error in JNI native functions
See Also:
Constant Field Values
KEY_COMMAND

public static final java.lang.String KEY_COMMAND
The key to put/retrieve the command data to/from bundle
See Also:
Constant Field Values
KEY_CMD_RESULT

public static final java.lang.String KEY_CMD_RESULT
The key to put/retrieve data the learnt command to/from bundle
See Also:
Constant Field Values
KEY_RESULT_ID

public static final java.lang.String KEY_RESULT_ID
The key to put/retrieve the generated UUID for a request to/from bundle
See Also:
Constant Field Values
KEY_DISCARD_ID

public static final java.lang.String KEY_DISCARD_ID
The key to put/retrieve the target UUID of a request to discard
See Also:
Constant Field Values
KEY_DROPPABLE

public static final java.lang.String KEY_DROPPABLE
The key to put/retrieve the boolean flag to indicate a request is can be dropped or not
See Also:
Constant Field Values
KEY_TIMEOUT

public static final java.lang.String KEY_TIMEOUT
The key to put/retrieve the timeout value for learning
See Also:
Constant Field Values
Constructor Detail
CIRControl

public CIRControl(Context context,
Handler handler)
the CIRControl constructor
Parameters:
context - the Context of application
handler - Handler for receiving result or request

Method Detail
isStarted

public boolean isStarted()
check if service has been already started successfully
Returns:
true if it is bound
start

public void start()
bind to CIRModule service
stop

public void stop()
unbind to CIRModule service
getFirmwareVersion

public java.util.UUID getFirmwareVersion()
get the firmware version of CIR module
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
cancelCommand

public java.util.UUID cancelCommand()
cancel the on-going command
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
discardCommand

public java.util.UUID discardCommand(java.util.UUID uuid)
discard the specific commands in queue
Parameters:
uuid - specific the target command with its UUID value
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
reset

public java.util.UUID reset()
reset the hardware of CIR module
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
transmitIRCmd

public java.util.UUID transmitIRCmd(abcIrData irData,
boolean droppable)
generate IR signals according to information in the abcIrData
Parameters:
irData - contains the information of generating IR signals
droppable - if true, command can be dropped when IR is running and busy
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
learnIRCmd

public java.util.UUID learnIRCmd(int timeout)
enter learning mode to learn IR signals as a command
Parameters:
timeout - the period of time before learning process expires if the CIR module cannot detect valid IR signals frames
Returns:
get the UUID assigned to this request; null represents service is not brought up yet

com.abc.abcircontrol
Class abcIrData

java.lang.Object
com.abc.abcircontrol.abcIrData

All Implemented Interfaces:
java.io.Serializable
public class abcIrData
extends java.lang.Object
implements java.io.Serializable
abcCalendar

See Also:
Serialized Form

Field Summary
static java.lang.String TAG
the logcat tag string

Constructor Summary
abcIrData()
default constructor
abcIrData(int rc, int freq, int[] array)
the abcIrData constructor


Method Summary
int[] getFrame()
get the IR learning data frame
int getFrequency()
get the carrier frequency
int getPeriod()
get the time period that is needed by sending an IR
int getPeriodTolerance()
get the tolerance of time period which is needed to send an IR
int getRepeatCount()
get the number of repeat counts
void setFrame(int[] array)
set the IR data frame
void setFrequency(int val)
set the carrier frequency
void setPeriod(int period)
set the time period that is needed by sending an IR
void setPeriodTolerance(int percent)
set the tolerance percentage of time period that is needed to send an IR
void setRepeatCount(int val)
set the number of repeat counts

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Field Detail
TAG

public static final java.lang.String TAG
the logcat tag string
See Also:
Constant Field Values
Constructor Detail
abcIrData

public abcIrData()
default constructor
abcIrData

public abcIrData(int rc,
int freq,
int[] array)
the abcIrData constructor
Parameters:
rc - the number of repeat counts
freq - carrier frequency (i.e., 38400 is 38.4KHz)
array - data frame in integer array


Method Detail
getRepeatCount

public int getRepeatCount()
get the number of repeat counts
Returns:
the number of repeat counts in integer
setRepeatCount

public void setRepeatCount(int val)
set the number of repeat counts
Parameters:
val - number of repeat counts
getFrequency

public int getFrequency()
get the carrier frequency
Returns:
get the carrier frequency in integer
setFrequency

public void setFrequency(int val)
set the carrier frequency
Parameters:
val - carrier frequency (ie., 38400 is 38.4KHz)
getFrame

public int[] getFrame()
get the IR learning data frame
Returns:
get the data frame in array
setFrame

public void setFrame(int[] array)
set the IR data frame
Parameters:
array - data frame to send IR key
getPeriod

public int getPeriod()
get the time period that is needed by sending an IR
Returns:
get the time period in msec
setPeriod

public void setPeriod(int period)
set the time period that is needed by sending an IR
Parameters:
period - time period in msec
getPeriodTolerance

public int getPeriodTolerance()
get the tolerance of time period which is needed to send an IR
Returns:
get the tolerance of time period in 0 ~ 100 percentage
setPeriodTolerance

public void setPeriodTolerance(int percent)
set the tolerance percentage of time period that is needed to send an IR
Parameters:
percent - tolerance in 0 ~ 100 percentage

com.abc.abcircontrol
Class abcIrInterface

java.lang.Object
com.abc.abcircontrol.abcIrInterface
public class abcIrInterface
extends java.lang.Object
abcIrInterface



Field Summary
static int CIR_CANCEL
IR cancel occurs
static int CIR_CANCEL_ERROR
fail to cancel IR activity
static int CIR_CHECKSUM_ERROR
command checksum error
static int CIR_COMPLETION
IR completed without error
static int CIR_INVALID_VALUE
Invalid argument or data in IR command
static int CIR_LEARNING_TIMEOUT
IR learning timeout occurs
static int CIR_OBJ_ERROR
object error in JNI native function
static int CIR_OUT_OF_FREQ
IR learning data frequency is not supported
static int CIR_PIPE_ERROR
fail to create/read/write pipe
static int CIR_PULSE_ERROR
pulse error in IR data
static int CIR_TTY_READ_ERROR
IR hardware read error
static int CIR_TTY_SETUP_ERROR
IR hardware init error
static int CIR_TTY_WRITE_ERROR
IR hardware write error
static int CIR_UNKNOWN_ERROR
unknown error is from IR hardware component

Constructor Summary
abcIrInterface()
default constructor


Method Summary
static int cancelIR()
cancel IR activity in IR hardware
static int doReset()
reset IR hardware
static int enableIR(int on)
enable IR hardware
static int getFirmwareVersion()
get IR firmware revision
static abcIrData learnIR(int seconds)
learn IR key from remotes
static int[] loadAndSendIR(int cmdId, int repeatCount, int freq, int[] cmdBytes)
send IR key
static int[] receiveIR(int seconds)
receive IR data (key) from remotes
static int[] sendIR(int[] cmdBytes)
send IR key
static int transmitIR(abcIrData irData)
send IR to appliances

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Field Detail
CIR_COMPLETION

public static final int CIR_COMPLETION
IR completed without error
See Also:
Constant Field Values
CIR_TTY_SETUP_ERROR

public static final int CIR_TTY_SETUP_ERROR
IR hardware init error
See Also:
Constant Field Values
CIR_TTY_WRITE_ERROR

public static final int CIR_TTY_WRITE_ERROR
IR hardware write error
See Also:
Constant Field Values
CIR_TTY_READ_ERROR

public static final int CIR_TTY_READ_ERROR
IR hardware read error
See Also:
Constant Field Values
CIR_INVALID_VALUE

public static final int CIR_INVALID_VALUE
Invalid argument or data in IR command
See Also:
Constant Field Values
CIR_LEARNING_TIMEOUT

public static final int CIR_LEARNING_TIMEOUT
IR learning timeout occurs
See Also:
Constant Field Values
CIR_CANCEL_ERROR

public static final int CIR_CANCEL_ERROR
fail to cancel IR activity
See Also:
Constant Field Values
CIR_CHECKSUM_ERROR

public static final int CIR_CHECKSUM_ERROR
command checksum error
See Also:
Constant Field Values
CIR_OUT_OF_FREQ

public static final int CIR_OUT_OF_FREQ
IR learning data frequency is not supported
See Also:
Constant Field Values
CIR_CANCEL

public static final int CIR_CANCEL
IR cancel occurs
See Also:
Constant Field Values
CIR_PULSE_ERROR

public static final int CIR_PULSE_ERROR
pulse error in IR data
See Also:
Constant Field Values
CIR_PIPE_ERROR

public static final int CIR_PIPE_ERROR
fail to create/read/write pipe
See Also:
Constant Field Values
CIR_OBJ_ERROR

public static final int CIR_OBJ_ERROR
object error in JNI native function
See Also:
Constant Field Values
CIR_UNKNOWN_ERROR

public static final int CIR_UNKNOWN_ERROR
unknown error is from IR hardware component
See Also:
Constant Field Values
Constructor Detail
abcIrInterface

public abcIrInterface()
default constructor
Method Detail
loadAndSendIR

public static int[] loadAndSendIR(int cmdId,
int repeatCount,
int freq,
int[] cmdBytes)
send IR key
Parameters:
cmdId - only support send command 4
repeatCount - number of repeat counts
freq - carrier frequency
cmdBytes - frame data bytes
Returns:
reply packet data including error status
sendIR

public static int[] sendIR(int[] cmdBytes)
send IR key
Parameters:
cmdBytes - command data stream
Returns:
reply packet data including error status
receiveIR

public static int[] receiveIR(int seconds)
receive IR data (key) from remotes
Parameters:
seconds - timeout period
Returns:
data frame including repeat count, carrier frequency, and IR frame data
getFirmwareVersion


public static int getFirmwareVersion()
get IR firmware revision
Returns:
revision number
doReset

public static int doReset()
reset IR hardware
Returns:
to indicate success (0) or failure
cancelIR

public static int cancelIR()
cancel IR activity in IR hardware
Returns:
to indicate success (0) or failure
enableIR

public static int enableIR(int on)
enable IR hardware
Parameters:
on - true to enable, false to disable
Returns:
to indicate success (0) or failure
transmitIR

public static int transmitIR(abcIrData irData)
send IR to appliances
Parameters:
irData - abcIrData is defined in class abcIrData
Returns:
error status is prefix CIR_
learnIR

public static abcIrData learnIR(int seconds)
learn IR key from remotes
Parameters:
seconds - timeout period
Returns:
refer to class abcIrData
 

agraham

Expert
Licensed User
I am trying to simulate the abcIrData constructor using my own type (ABCData)
You can't, it won't work.

Your reflection code is miles off I'm afraid.

You need a Handler and a Context instance to pass to the CIRControl constructor.
You can create the Handler by reflection and use the Reflection.getContext for the context.
You need an abcIrData instance to pass to transmitIRCmd

Something like the following which won't work because I can't test it. It would be easier to knock up a library which in turn would be easier to add more functionality to.
B4X:
'Send command using built-in IR port
Dim rc, rh, rd As Reflector

' Handler
rh.Target = rh.CreateObject("android.os.Handler")

'com.abc.circontrol.CIRControl
Dim types(2) As String
Dim args(2) As Object
types(0) = "android.content.Context"
args(0) = rh.GetContext
types(1) = "android.os.Handler"
args(1) = rh.Target
rc.Target = rc.CreateObject2("com.abc.circontrol.CIRControl", args, types)

'com.abc.circontrol.abcIrData 
Dim types(3 As String
Dim args(3) As Object
types(0) = "I"
args(0) = rcValueorVar ' probably need an int var not a literal to get an int type
types(1) = "I"
args(1) = freqValueOrVar ' probably need an int var not a literal to get an int type
types(1) = "[I"
args(1) = intArrayVar
rd.Target = rd.CreateObject2("com.abc.circontrol.abcIrData",args, types)

'run transmitIRCmd method
Dim types(2) As String
Dim args(2) As Object
types(0) = "com.abc.circontrol.abcIrData"
args(0) = rd.Target
types(1) = "Z"
args(1) = boolvar ' probably need a boolean var not a literal to get a boolean type
rc.RunMethod4("transmitIRCmd", args, types)
 
Last edited:
Upvote 0

Kevin

Well-Known Member
Licensed User
Thanks!

I have the correct phone to test this on but I am receiving the following error when running the app:

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException:

This occurs on the following line:

B4X:
rd.Target = rd.CreateObject2("com.abc.abcircontrol.abcIrData", args, types)

(and for the record, yes I changed the actual code to use the correct package name).

The docs say that abcIrData is in fact part of that package, so I don't know why the error is occurring. :(
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Still no joy...


shortcutexec_vvvvvvvvvvvvvvvvvvvvvv7 (java line: 2795)


java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.abc.abcircontrol.CIRControl$abcIrData
at anywheresoftware.b4a.agraham.reflection.Reflection.CreateObject2(Reflection.java:257)
at com.cognitial.dtvvoltest.shortcutexec._vvvvvvvvvvvvvvvvvvvvvv7(shortcutexec.java:2795)
at com.cognitial.dtvvoltest.shortcutexec._vvvvvvvvvvvvvvvvvvvvvvv4(shortcutexec.java:2447)
at com.cognitial.dtvvoltest.shortcutexec._vvvvvvvvvvvvvvvvvvvvv3(shortcutexec.java:1135)
at com.cognitial.dtvvoltest.shortcutexec._activity_resume(shortcutexec.java:314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at com.cognitial.dtvvoltest.shortcutexec.afterFirstLayout(shortcutexec.java:95)
at com.cognitial.dtvvoltest.shortcutexec.access$100(shortcutexec.java:16)
at com.cognitial.dtvvoltest.shortcutexec$WaitForLayout.run(shortcutexec.java:74)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.abc.abcircontrol.CIRControl$abcIrData
at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:159)
at anywheresoftware.b4a.agraham.reflection.Reflection.CreateObject2(Reflection.java:250)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.abc.abcircontrol.CIRControl$abcIrData
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:156)
... 21 more
Caused by: java.lang.NoClassDefFoundError: com/abc/abcircontrol/CIRControl$abcIrData
... 25 more
Caused by: java.lang.ClassNotFoundException: com.abc.abcircontrol.CIRControl$abcIrData
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 25 more
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.abc.abcircontrol.CIRControl$abcIrData
** Activity (shortcutexec) Pause, UserClosed = false **

Just not having much luck with this one... :confused:
 
Upvote 0

Kevin

Well-Known Member
Licensed User
B4X:
' Handler
Dim rh As Reflector
rh.Target = rh.CreateObject("android.os.Handler")

'com.abc.circontrol.CIRControl
Dim rc As Reflector
Dim types(2) As String
Dim args(2) As Object
types(0) = "android.content.Context"
args(0) = rh.GetContext
types(1) = "android.os.Handler"
args(1) = rh.Target
rc.Target = rc.CreateObject2("com.abc.circontrol.CIRControl", args, types)

'com.abc.circontrol.abcIrData
Dim rd As Reflector
Dim types(3) As String
Dim args(3) As Object
types(0) = "I"
args(0) = abcDat.rc
types(1) = "I"
args(1) = abcDat.freq
types(1) = "[I"
args(1) = irArray
rd.Target = rd.CreateObject2("com.abc.abcircontrol.CIRControl$abcIrData", args, types)

'run transmitIRCmd method
Dim types(2) As String
Dim args(2) As Object
types(0) = "com.abc.abcircontrol.CIRControl$abcIrData"
args(0) = rd.Target
types(1) = "Z"
args(1) = False ' might need a boolean var not a literal to get a boolean type
rc.RunMethod4("transmitIRCmd", args, types)
 
Upvote 0

agraham

Expert
Licensed User
I see a cut and paste error in the indices for types(2) and args(2). Try
B4X:
Dim types(3 As String
Dim args(3) As Object
types(0) = "I"
args(0) = rcValueorVar ' probably need an int var not a literal to get an int type
types(1) = "I"
args(1) = freqValueOrVar ' probably need an int var not a literal to get an int type
types(2) = "[I"
args(2) = intArrayVar
rd.Target = rd.CreateObject2("com.abc.circontrol.abcIrData",args, types)
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Darn cut & paste errors will get you every time! :) I missed that as well.

Unfortunately even after fixing that, I am still getting the class not found errors. I'm really not sure why though.

I don't want to take any more of your time on it though. thedesolatesoul was able to make a library for me and we got it working this morning.

I did learn a bit about reflection though so it wasn't all for naught. Hopefully others might learn from it as well.

Thanks!
 
Upvote 0

ivan.tellez

Active Member
Licensed User
I know, its a really old post, but, if some one have a similar issue, the solution its really simple.


Your "abc" (htc) object is not part of Android, you have to put the JAR in the libs folder and the include it with the AdditionalJar


B4X:
#AdditionalJar: HTCIR
 
Upvote 0
Top