public class MyClass extends javax.swing.JDialog
{
public MyClass()
{
this((Frame)null);
}
public void setVisible(boolean b)
{
if (b)
setLocation(50, 50);
super.setVisible(b);
}
static public void main(String args[])
{
(new MyClass()).setVisible(true);
}
}
// Runtime error
JDK 1.2
Exception occurred during event dispatching:
java.lang.IllegalArgumentException: argument type mismatch
at java.lang.reflect.Method.invoke(Native Method)
at Debug.invokeClass(Debug.java:304)
at Debug.InvokeactionPerformed(Debug.java:320)
JDK 1.4
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at Debug.invokeClass(Debug.java:304)
at Debug.InvokeactionPerformed(Debug.java:320)
Last edited by Yury; April 20th, 2004 at 12:34 PM.
You can't get a runtime error with the code you posted because it doesn't even compile - not only is PasswordDialog undefined, but in your MyClass constructor you try to call this((Frame) null); when you don't have a constructor that takes a Frame.
I suspect this line:
Code:
Class array[] = {java.lang.Class.forName("[Ljava.lang.String;")};
doesn't help.
If you post the code that actually compiles and produces the runtime error, I might take a bit more interest...
It is better to have an approximate answer to the right question than an exact answer to the wrong one...
J. Tukey
Last edited by dlorde; April 20th, 2004 at 08:33 AM.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
please note also, that the following statements are NOT equivalent:
String args[] = new String[1];
String args[] = {""};
the following two equivalences are correct:
PHP Code:
String args[] = new String[1];
String args[] = new String[]{null};
or
PHP Code:
String args[] = {""};
String args[] = new String[1];
args[0] = "";
-
from my brief investigations, it appears that the invoke method expects two parameters, the second of which is the arguments
The arguments are an array of type Object[], length of 1, and the value at index 0 must be null
the following codes do not produce an error:
Code:
String[] args = new String[1];
String[] args = new String[]{null};
Object[] args = new Object[1];
Object[] args = new Object[]{null};
Originally posted by Yury
static public void main(String args[])
Don't you have to write public static void main in that specific order? I've never tried your order, but I've had issues in other areas when mixing up the order of things, like instance variables.
Originally posted by Demonpants Software
Don't you have to write public static void main in that specific order? I've never tried your order, but I've had issues in other areas when mixing up the order of things, like instance variables.
Nope, static public void main(String[] args) is exactly the same as public static void main(String[] args). What you can't do (in any method) is static void public main(String[] args) as the return type is assumed to be the LAST modifier, so whatever comes after the return type is assumed to be the identifier. Since neither static or public are valid identifiers because they're keywords, that wouldn't be allowed.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.