Class.forName and casting
Hi there. I'm doing a bit of Android development and I stumbled across a problem :)
obj is an instance of the class receiver_Class. I'm sure that I have the correct receiver_Class cuz I tried printing its methods and they appear correct. I'm sure I have the correct instance, obj because it's not null :) The problem is how to combine them in a useful way.
Class<?> receiver_Class = Class.forName(FM_RECEIVER_PATH);
Object obj = getSystemService(FM_SERVICE);
I don't have the source of the class but I have the decomiled .slimi file and I was able to reconstruct an interface that has all the methods inside the class. The problem is that when I try
where the IFMRadio is the interface I reconstructed, I get a ClassCastException error.
IFMRadio receiver = (IFmReceiver) receiver_Class.cast(obj);
Can somebody help me :)
returns true :)
I put IFMRadio into a FM_RECEIVER_PATH package and the casting stopped throwing that error. But now when I try to invoke a method, the app on the phone just freezes :( I tried making IFMRadio an asbtract class instead of an interface and now everything just returns the default value for its type (like 0 if the procedure is due to return an int).
And another update:
I tried invoking a method by using Method.invoke on an object that has been assigned to receiver_Class.cast(obj). No errors occurred and the results were still 0s which might mean that using of an abstract class does work and the function I'm testing is supposed to return a value 0. But anyway I will need to cast that thing to a class or an interface, so I could be able to override some methods of a remote listener class.
Do you thing casting on an abstract class actually worked?