Mit Java-Konstruktor.newInstance(args) , warum die "falsche Anzahl von Argumente" Fehler?

Warum hat dieses scheitern mit der Fehlermeldung :

Args are: -normi -nosplash
Exception in thread "main" java.lang.IllegalArgumentException: wrong 
     number of arguments
    at sun.reflect.NativeConstructorAccessorImpl
    .newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl
    .newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl
    .newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at TSStack.main(TSStack.java:14)

Hier ist der code:

public static void main(String args[]) throws Exception {
    System.out.println("Args are: " + args[0]+ " " + args[1] );
        try {
            Constructor<Site> c = Site.class.getDeclaredConstructor();
            c.setAccessible(true); //use reflection to get access to  
                                      //this private constructor
            c.newInstance( (Object[])args );
          } catch (InvocationTargetException x) {
            x.printStackTrace();
          } catch (NoSuchMethodException x) {
            x.printStackTrace();
          } catch (InstantiationException x) {
            x.printStackTrace();
          } catch (IllegalAccessException x) {
            x.printStackTrace();
          }     
}
  • Niedlich - Sie versucht zu fangen, eine ganze Reihe von Ausnahmen, aber landete trotzdem fehlt trotzdem.
  • Würde keinen Unterschied machen.
InformationsquelleAutor djangofan | 2011-07-24
Schreibe einen Kommentar