title: Java wrong number of arguments
body: <p>When runing this method i get wrong number of arguments exception like this :</p>
  
  <pre class="lang-none prettyprint-override"><code>Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: wrong number of arguments
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at javafxcyberwind.Participant_MethodsIMPL.execution(Participant_MethodsIMPL.java:85)
  </code></pre>
  
  <p>The exception is in the comment line, despite the arguments entered are correct, this is my code:</p>
  
  <pre><code> @Override
   public void execution(String cls, String ip, Object... par) throws InvocationTargetException, RemoteException {
          try {
              URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file:///" + prep)});
              Class&lt;?&gt; c = loader.loadClass(cls);
              Object j = c.newInstance();
              Method[] methods = c.getDeclaredMethods();
              for (Method method : methods) {
                  ArrayList&lt;Object&gt; tab = new ArrayList&lt;&gt;();
                  if (method.getReturnType() == int.class || method.getReturnType() == String.class || method.getReturnType() == boolean.class || method.getReturnType() == double.class) {
                  tab.clear();
                  tab.addAll(Arrays.asList(par));
                  int i = 0;                    
                  HashMap&lt;Integer, File&gt; lif = new HashMap&lt;&gt;();
                  File file = null;
                  for (Object o : tab) {
                      if (o.getClass().equals(Fichier.class)) {
                          String nomfichier = ((Fichier) o).getNom();
                          file = new File(prep + nomfichier);                            
                          lif.put(i, file);
                      }
                      i++;
                  }                 
                  for (Map.Entry&lt;Integer, File&gt; entry : lif.entrySet()) {
                      tab.remove(entry.getKey());
                      tab.add(entry.getKey(), entry.getValue());
                  }
                  k = method.invoke(j, tab.toArray());//line of exception
                  if (file != null) {
                      file.delete();
                  }
              }
                  if (method.getReturnType().toString().equals("class java.io.File")) {
                      tab.clear();
                      tab.addAll(Arrays.asList(par));
                      int i = 0;
                      int t = -1;
                      String nomfichier = null;
                      File file = null;
                      for (Object o : tab) {
                          if (o.getClass().equals(Fichier.class)) {
                              nomfichier = ((Fichier) o).getNom();
                              file = new File(prep + nomfichier);
                              t = i;
                          }
                          i++;
                      }
                      if (t != -1) {
                          tab.remove(t);
                          tab.add(t, file);
                      }
                      k = method.invoke(j, tab.toArray());
                      if (file != null) {
                          file.delete();
                      }
                      fff = nomfichier.replace(nomfichier, cls + "_" + nomfichier);
                      File fres = new File(prep + fff);
                      R.uploadToCloud(fff);
                      Socket s = new Socket(ip, R.getPort());
                      FileInputStream inf = new FileInputStream(fres);
                      ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
                      byte buf[] = new byte[1024];
                      int n;
                      while ((n = inf.read(buf)) != -1) {
                          out.write(buf, 0, n);
                      }
                      out.close();
                      inf.close();
                      s.close();
                      fres.delete();
                  }
              }
          } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
              Logger.getLogger(Participant_MethodsIMPL.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  </code></pre>
  
  <p>I can avoid the exception and make it work but as you see just for one file passed as an argument, this is the code :</p>
  
  <pre><code>if (method.getReturnType() == int.class || method.getReturnType() == String.class || method.getReturnType() == boolean.class || method.getReturnType() == double.class) {
                  tab.clear();
                  tab.addAll(Arrays.asList(par));
                  int i = 0;
                  int t = -1;
                  File file = null;
                  for (Object o : tab) {
                      if (o.getClass().equals(Fichier.class)) {//means there is an argument of type File
                          String nomfichier = ((Fichier) o).getNom();//getting the file name
                          file = new File(prep + nomfichier);//file that will replace the remote file
                          t = i;
                      }
                      i++;
                  }
                  if (t != -1) {//replacing the remote file
                      tab.remove(t);
                      tab.add(t, file);
                  }
                  k = method.invoke(j, tab.toArray());
                  if (file != null) {
                      file.delete();
                  }
              }
  </code></pre>
  
  <p>This method is called remotely so i have to create a new file for each file passed as an argument known that the files are received in advance. 
  The problem is when passing more than one file as an argument, in this case, how can i create a list of files where each file have an id that equals <code>i</code> then just browse this list ? I tried to do this with <code>HashMap</code> like on top but i keep getting the exception !  </p>