Cannot resolve the "e" in e.getKeyCode(); - keyevent

im trying to implement a Key Event, but eclipse can't resolve the "e" in e.getKeyCode();
What am I missing here?
Error

You don't have e defined in your code. You have your method signature as:
public void keyPressed(KeyEvent arg0)
Either change arg0 to e or vice versa.

Related

how to create a KeyUp event in a legacy C++ CLR:syntax application

I am trying to change a legacy C++ CLR:oldsyntax application to set up an KeyUp event without success.
This is the relevant part of the code:
// declare delegate
__delegate void KeyUpFuncDelegate(Object */*sender*/, System::Windows::Forms::KeyEventArgs * e);
// try to hook up the event
this->SuperMatricula->KeyUp+= KeyEventHandler(this,KeyUpFuncDelegate);
I get the following error:
error C2275: 'GrFingerSampleCPPdotNET2005::FormSup::KeyUpFuncDelegate' : illegal
use of this type as an expression
Any clue?
Thanks in advance!
I think you just need to change it to delegate and make sure the event uses that delegate. An example ripped out of some of code for comparison.
.h
private ref class StatusMgr sealed
{
public:
delegate void StatusTextChangedEventHandler( System::Object^ sender, StatusTextChangedEventArgs^ args );
event StatusTextChangedEventHandler^ StatusTextChanged;
.cpp
statusMgr->StatusTextChanged +=
gcnew StatusMgr::StatusTextChangedEventHandler( this, &StatusBarTextItem::onStatusTextChanged );

SqsListener String index out of bounds issue

I'm encountering a really weird problem when trying to use the #SQSListener annotation from the Spring Cloud module.
Here's my listener method:
#SqsListener(value = "myproject-dev-au-error-queue")
public void listenPhoenix(String message) throws IOException {
logger.info(message);
}
However, once I run the project, it starts reading messages from the queue and fails with the following error:
Exception in thread "simpleMessageListenerContainer-4" Exception in thread "simpleMessageListenerContainer-6" Exception in thread "simpleMessageListenerContainer-9" Exception in thread "simpleMessageListenerContainer-10" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1931)
at org.springframework.cloud.aws.messaging.core.QueueMessageUtils.getNumberValue(QueueMessageUtils.java:93)
at org.springframework.cloud.aws.messaging.core.QueueMessageUtils.getMessageAttributesAsMessageHeaders(QueueMessageUtils.java:80)
at org.springframework.cloud.aws.messaging.core.QueueMessageUtils.createMessage(QueueMessageUtils.java:56)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.getMessageForExecution(SimpleMessageListenerContainer.java:375)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:336)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:392)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
With the problematic part being in the spring-cloud-aws-messaging module QueueMessageUtils class numberType variable assignment:
private static Object getNumberValue(MessageAttributeValue value) {
String numberType = value.getDataType().substring("Number".length() + 1);
try {
Class<? extends Number> numberTypeClass = Class.forName(numberType).asSubclass(Number.class);
return NumberUtils.parseNumber(value.getStringValue(), numberTypeClass);
} catch (ClassNotFoundException var3) {
throw new MessagingException(String.format("Message attribute with value '%s' and data type '%s' could not be converted into a Number because target class was not found.", value.getStringValue(), value.getDataType()), var3);
}
}
Has anyone seen this before and if so is there a way to fix this?
P.S: Since I don't really care about the message attributes I wouldn't mind if they were completely ignored.
Thanks in advance.
The exception in the given code is thrown from the following line.
String numberType = value.getDataType().substring("Number".length() + 1);
According to the documentation in AWS JAVA SDK,it explains how the getDataType() function works (See this link). According to the documentation, it will return one of the following values.
String
Number
Binary
Amazon SQS supports the following logical data types: String, Number,
and Binary. For the Number data type, you must use StringValue.
Now, when you call value.getDataType(), it will return one of the above values. Assuming it's "Number", you are trying to get a substring of it, starting from index 6 (where "Number".length() + 1 = 6)
But there is no such index in the String returned by value.getDataType(). Therefore, it will throw a java.lang.StringIndexOutOfBoundsException exception.
As a solution for this, you can simply use the following instead of getting the substring of it.
String numberType = value.getDataType();
I have also face the same issue, when publishing message with SQS Extended Library, it automatically added one attribute along with the message SQSLargePayloadSize with the datatype Number which is causing the problem. the exception is resolved by updating the dependency from
implementation group: 'org.springframework.cloud', name: 'spring-cloud-aws-messaging', version: '2.2.6.RELEASE'
to any latest version of awspring spring-cloud-aws-messaging
implementation group: 'io.awspring.cloud', name: 'spring-cloud-aws-messaging', version: '2.4.1'
make sure all the package must be imported from io.awspring.cloud

Xamarin.Android - Binding a Constructor which throws an Exception

I created a Xamarin Binding Project for Android, and generated the Bindings for the .aar file. So far, so good.
When I first called a constructor which throws an Exception, a build error occured:
.../XamVideoCaptureReader.java(9,9): Error: error: unreported exception ReaderException; must be caught or declared to be thrown super (p0, p1, p2); (AndroidTest)
On the following code part:
public XamVideoCaptureReader (int p0, com.digimarc.dms.readers.ReaderOptions p1, com.digimarc.dms.readers.image.CaptureFormat p2)
{
super (p0, p1, p2);
...
}
I think the error is pretty self explanatory, but I can't find a way to fix it. The super call has to be wrapped in a try catch, or even better: a throws ReaderException should be added to the constructor signature.
Has anyone experienced this error before and could solve it? Or is this a bug of Xamarin?

rxBindings - How to know what consumer type should be when debouncing click events?

using rxBindings im trying to slow down a click event but i would like to know what the parameter is need.
For example, here is a call i am doing on a imageview. So ImageView v;
RxView.clicks(v)
.throttleFirst(400, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.subscribe(new Consumer<Object>() {
#Override
public void accept(#io.reactivex.annotations.NonNull Object v) throws Exception {
showBottomSheet(getAdapterPosition());
}
});
but im im not sure what the parameter in accept should be ?
I was expecting i would get the view here but when i try changing the type to View i get an error of no such method.
If you look at the source code of the Observable generate using RxView.clicks(), you will see that when the click happens, the following code is triggered:
observer.onNext(Notification.INSTANCE);
that is defined in the library, as:
public enum Notification {
INSTANCE
}
It is just a convenient way for indicating that the event happened, it doesn't carry any extra information.

How to create a custom Sonar rule to check if a method throws a certain exception?

So we want to check a certain method, say findOne() in certain java classes if it throws a specific exception or not. If it doesn't throw the exception, then an issue to be reported at method level.
We could use
public void visitThrowStatement(ThrowStatementTree tree)
but this only gets called when there is a statement that throws the exception, how can we check if it's not thrown?
You need to keep a context in your visitor to know in which method you are currently visiting throw statements.
Basically, if you are within a findOne method, then you will visit the code of the method, if it has a correct throw statement,then don't raise an issue but if it has not then raise an issue.
Something along the lines of (this is pseudo code and should of course be adapted but that will explain the concept):
LinkedList<MethodTree> stack;
int throwCount = 0;
void visitMethod(MethodTree methodTree) {
stack.push(methodTree);
throwCount = 0;
super.visitMethod(methodTree);
if(throwCount == 0) {
//raise Issue
}
}
void visit throwStatement(ThrowStatementTree tree) {
if(isCorrectExceptionThrown(tree)) {
throwCount++;
}
}

Resources