-
April 13th, 2017, 10:53 PM
#1
key handler problems
Here is my code:
Code:
=jtextfield1.addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_ENTER)
{ jtextfield1.getText();
JOptionPane.showMessageDialog(null,null,"Success",JOptionPane.INFORMATION_MESSAGE);
}
)};
}
I am getting these errors
java.lang.ClassFormatError: Invalid superclass index 0 in class file MycologyFrame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Error: A JNI error has occurred, please check your installation and try again
I have the proper imports in there too. I basically followed a youtube on it and mine isn't working . I don't know why ? Help
Last edited by Azoth; April 13th, 2017 at 10:55 PM.
-
April 14th, 2017, 06:04 AM
#2
Re: key handler problems
Why do you think the error is related to the posted code?
How are you using JNI?
Norm
-
April 14th, 2017, 07:01 AM
#3
Re: key handler problems
Originally Posted by Norm
Why do you think the error is related to the posted code?
How are you using JNI?
When I remove the key handler my program run just fine.
-
April 14th, 2017, 07:06 AM
#4
Re: key handler problems
I have no idea why that code would cause an exception.
What happens if the JOptionPane statement is removed?
What is the = that is shown in the posted code:
=jtextfield1.addKeyListener(new KeyAdapter(){
Norm
-
April 14th, 2017, 09:14 AM
#5
Re: key handler problems
Originally Posted by Norm
I have no idea why that code would cause an exception.
What happens if the JOptionPane statement is removed?
What is the = that is shown in the posted code:
=jtextfield1.addKeyListener(new KeyAdapter(){
Typo
-
April 14th, 2017, 01:28 PM
#6
Re: key handler problems
Does the code compile without errors?
Are you trying to run the code with compiler errors?
Norm
-
April 14th, 2017, 04:12 PM
#7
Re: key handler problems
Originally Posted by Norm
Does the code compile without errors?
Are you trying to run the code with compiler errors?
I removed the Popup window and put in a System.out.println("success") but
upon running it printed nothing.
I tried something like this
Class appname extends jframe implements keyHandler{
I get the error class appname not abstract ?
Last edited by Azoth; April 14th, 2017 at 04:14 PM.
-
April 14th, 2017, 04:40 PM
#8
Re: key handler problems
That means the code was not executed.
Is the keyPressed method called? Add a print statement to show if it was called and what the value of the passed key code was.
Norm
-
April 14th, 2017, 05:00 PM
#9
Re: key handler problems
Originally Posted by Norm
That means the code was not executed.
Is the keyPressed method called? Add a print statement to show if it was called and what the value of the passed key code was.
Pressing enter should call it. How do do I call it?
-
April 14th, 2017, 05:07 PM
#10
Re: key handler problems
Can you make a small, simple program for testing that shows the problem?
Norm
-
April 15th, 2017, 07:20 AM
#11
Re: key handler problems
Problem solved.i had to change keyevent e to java.awt.event.KeyEvent in the parameter. It then recognized the
getKeyCode() method. Before it stated it could not find the symbol.
-
April 15th, 2017, 07:43 AM
#12
Re: key handler problems
it could not find the symbol.
When you get compiler errors, you MUST fix them before trying to execute the code.
It's a waste of time posting short pieces of code without also posting the error messages it has.
Norm
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|