Object.class.getMethod(methodName, Object.class);
is not getting executed by bsh.Interpreter and throwing exceptions
Typed variable declaration : reflection error: bsh.ReflectError: Method getMethod( java.lang.String, java.lang.Class ) not found in class'java.lang.Class'
Any idea how to fix this ?
Thanks in advance.
Beanshell doesn't support variable parameters, so you need to put it in an array as per older versions of the Java language.
Object.class.getMethod("equals", new Class[] { Object.class } );
Related
I response this error when get JSON data by retrofit.
List<NewLicense> result = null;
Call<List<NewLicense>> serviceResult = ShahrdariApp.getShahrdariWebService().getLicenses(Configuration.getInstance().getString(SharedPrefs.MAC_ADDRESS), id);
try {
Response<List<NewLicense>> response = serviceResult.execute();
result = response.body();
Log.d("responseCode", String.valueOf(response.code()) );
} catch (Exception e) {
exceptionHandling(e);
Log.d("responseCode", String.valueOf(e.getMessage()) );
}
return result;
I had the same issue and forgot to set the Project SDK added this and it resolved the issue.
Simply restarting the IDE via File -> Invalidate caches can often solve this issue.
I faced the message
Unable to evaluate the expression Cannot find source class for
java.util.List
in hovering a List field while debugging in IntelliJ IDEA 2022.1.3 (UltimateEdition).
Even though an SDK was assigned to my Project, it helped to visit
IDEA ->File ->Project Structure -> Platform Settings ->SDKs and re-assign the SDK already visible in the list.
Namely I assigned openjdk-1.8.0.302-1, applied "OK", after that it was possible to debug a List foo.
IDE restart after that may additionally be necessary.
When I am trying to compile the following code:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
I get the compiler error: 'An expression tree may not contain a tuple literal.'
So I also tried this:
var post = iPostService.GetAll().
Select(x => new ValueTuple<string, string>(x.Title, x.Author))
The result is runtime error:'Cannot resolve method Void .ctor(System.String, System.String) because the declaring type of the method handle System.ValueTuple`2[T1,T2] is generic. Explicitly provide the declaring type to GetMethodFromHandle.'
I googled to find out the solution to this problem but nothing really helpful.
Any help really appreciated.
Thanks
It works for me, create a tuple first and convert it to a ValueTuple:
var post = iPostService.GetAll().
Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())
Finally, I found out what wrong with my code:
I am using deferred execution so data won't load from the database when the constructor executed.
The solution is to add conversion operators before creating instance command.
Hope it works with your code.
I have a datatransformer in symfony 2:
namespace Techforge\ApartmentBundle\Form\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Common\Persistence\ObjectManager;
class SearchboxToCityTransformer implements DataTransformerInterface {
public function reverseTransform($string)
{
//...
if(!$city)
throw new TransformationFailedException(sprintf('City not found.'));
}
//...
I can't figure out how to catch this exception in my controller.
I thought it was going to be thrown upon a form bind:
$form->bindRequest($request);
But that doesn't appear to be the case (I tested this out, and also tested out other parts in my controller).
Also, I'm pretty sure that I triggered the exception because the field didn't appear in the parameter bag (nothing was returned from the reverseTrasnform() function.)
Anyone has any ideas?
The short answer is: you don't.
Take a look at Symfony\Component\Form\Form::bind()
try {
// Normalize data to unified representation
$normData = $this->clientToNorm($clientData);
$synchronized = true;
} catch (TransformationFailedException $e) {
}
So TransformationFailedException are silently ignored. The behaviors is a bit puzzling but more than likely you are trying to do validation inside of a transformer which is not what transformers were intended for.
Move the error checking code code to a validator and things should fall into place.
TransformationFailedExceptions will result in an invalid field in the form. If you want the exception to bubble up higher, throw a different exception.
Im trying to connect a Flash client to BlazeDS. There has been some success with this from others using the vanilla BlazeDS setup. However I'm using the new Spring BlazeDS Integration from springsource and running aground.
The flash client actually seems to be working in that I can see the correct data in the body of the returned object, but for some reason unknown it fails casting as an IMessage. It fails in PollingChannel.as on this line with the subject line error
var messageList:Array = msg.body as Array;
for each (var message:IMessage in messageList) <--
On application load I register a whole bunch of classes like so
registerClassAlias( "flex.messaging.messages.RemotingMessage", RemotingMessage );
registerClassAlias("mx.messaging.messages.IMessage", IMessage);
etc..
my code is basically
var channelSet:mx.messaging.ChannelSet = new mx.messaging.ChannelSet();
var channel:mx.messaging.channels.AMFChannel = new AMFChannel("my-amf", "http://localhost:8400/SpringA/messagebroker/amf");
channelSet.addChannel(channel);
var consumer:mx.messaging.Consumer = new Consumer();
consumer.channelSet = channelSet;
consumer.destination = "simple-feed";
consumer.subscribe();
consumer.addEventListener(MessageEvent.MESSAGE, test);
private function test(event:IMessage)
{
trace("msg..");
// breakpoint never makes it here
}
I have a flex client which works 100% with same destination/channel.
The error in the title means that you, for some reason, got an object that is not implementing or extending the IMessage interface, therefore the loop can not cast it in this part:
for each (var message:IMessage in messageList){
Either you should somehow make sure that you don't add anything that is not extending or implementing IMessage, or check if the variable IS actually ext./imp. it. Also - if you want to do that, you will have to change the for each like this:
for each (var obj in messageList){
if (obj is IMessage){
var message:IMessage = obj as IMessage;
// DO STUFF HERE
}
}
Add this Object mapping:
registerClassAlias("flex.messaging.io.ObjectProxy", ObjectProxy);
If on your Java VO objects you have overridden the hashcode() method, this situation could happen.
Remove the hashcode() override (if you are able to).
See my blog for the backstory on how I discovered this. http://squaredi.blogspot.com/2013/12/remoting-landmine-without-stack-trace.html
I had the same error when trying to send an actionscript object to the backend. My problem was that my c# equivalent object was missing an public parameterless constructor.
Presume that there are methodA() , methodB() and methodC().
And methodC() is called at the run-time.
Is is possible to know methodC() is called from what method?
I was thinking if CallStack can be read at the run-time for some checks? If yes, I think it should not be a big deal.
Any ideas?
Thanks!
Use the StackTrace and StackFrame classes. For example:
StackTrace stackTrace = new StackTrace();
StackFrame[] stackFrames = stackTrace.GetFrames();
foreach (StackFrame stackFrame in stackFrames)
{
string method = stackFrame.GetMethod().Name;
// do some stuff with method
}
Yes, the call stack can be read at runtime using StackTrace.GetFrames.