本帖最后由 杜光 于 2013-7-5 15:20 编辑
求解:关于“java.lang.IllegalArgumentException: wrong number of argumen”的解决办法
源代码如下:
- package com.yb.TestFile;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * ----------------------------
- * @描述 TODO
- * @author Michael
- * @日期 2013-7-4
- *-----------------------------
- */
- public class TestFile {
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- List<Integer> list = new ArrayList<Integer>(); //定义Integer泛型
- String str = "abc";
- Method[] method = list.getClass().getMethods(); //取得list的所有方法
- System.out.println(method.length);
- for(int i=0; i<method.length; i++) {
- System.out.println(method[i]); //遍历打印list的方法
- }
- //通过反射来执行list的第一个方法,第一个是list对象,代表该对象的方法,第二个是方法参数
- method[0].invoke(list,str);
- System.out.println(list.size());
- for(int i=0; i<list.size(); i++) {
- System.out.println(list.get(i));
- }
- }
- }
复制代码 =============运行结果如下=====================
35
public java.lang.Object java.util.ArrayList.clone()
public void java.util.ArrayList.add(int,java.lang.Object)
public boolean java.util.ArrayList.add(java.lang.Object)
public boolean java.util.ArrayList.contains(java.lang.Object)
public java.lang.Object java.util.ArrayList.get(int)
public int java.util.ArrayList.indexOf(java.lang.Object)
public boolean java.util.ArrayList.isEmpty()
public int java.util.ArrayList.lastIndexOf(java.lang.Object)
public int java.util.ArrayList.size()
public java.util.List java.util.ArrayList.subList(int,int)
public java.lang.Object[] java.util.ArrayList.toArray(java.lang.Object[])
public java.lang.Object[] java.util.ArrayList.toArray()
public boolean java.util.ArrayList.addAll(java.util.Collection)
public boolean java.util.ArrayList.addAll(int,java.util.Collection)
public java.util.Iterator java.util.ArrayList.iterator()
public boolean java.util.ArrayList.remove(java.lang.Object)
public java.lang.Object java.util.ArrayList.remove(int)
public void java.util.ArrayList.clear()
public java.lang.Object java.util.ArrayList.set(int,java.lang.Object)
public void java.util.ArrayList.ensureCapacity(int)
public void java.util.ArrayList.trimToSize()
public java.util.ListIterator java.util.ArrayList.listIterator()
public java.util.ListIterator java.util.ArrayList.listIterator(int)
public boolean java.util.ArrayList.removeAll(java.util.Collection)
public boolean java.util.ArrayList.retainAll(java.util.Collection)
public int java.util.AbstractList.hashCode()
public boolean java.util.AbstractList.equals(java.lang.Object)
public java.lang.String java.util.AbstractCollection.toString()
public boolean java.util.AbstractCollection.containsAll(java.util.Collection)
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.yb.TestFile.TestFile.main(TestFile.java:24)
请问红色部分异常如何解决啊???
|