object is not an instance of declaring class&argument type mismatch
2014-09-21 12:02
1426 查看
报错:
java.lang.IllegalArgumentException:
object is not an instance of declaring class
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:597)
at DesignPattern.DemoObserver.ConcreteObservable.notifyObserver(ConcreteObservable.java:55)
at DesignPattern.DemoObserver.ConcreteObservable.notifyObservers(ConcreteObservable.java:36)
at DesignPattern.DemoObserver.Text.main(Text.java:19)
说明Class没有实例化;
解决办法:
由于没有实例化,可以有如下两种方法:
1、反射方法定义成为static的,故被反射类就不需要实例化;
2、method.invoke(_class.newInstance(), args);
报错:argument type mismatch
参数错误:
方法由public void update(Observer... objs) {}改为public
void update(Observer objs)即可。因为实际调入时传入的是单个对象 obj。
java.lang.IllegalArgumentException:
object is not an instance of declaring class
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:597)
at DesignPattern.DemoObserver.ConcreteObservable.notifyObserver(ConcreteObservable.java:55)
at DesignPattern.DemoObserver.ConcreteObservable.notifyObservers(ConcreteObservable.java:36)
at DesignPattern.DemoObserver.Text.main(Text.java:19)
说明Class没有实例化;
解决办法:
由于没有实例化,可以有如下两种方法:
1、反射方法定义成为static的,故被反射类就不需要实例化;
2、method.invoke(_class.newInstance(), args);
报错:argument type mismatch
参数错误:
方法由public void update(Observer... objs) {}改为public
void update(Observer objs)即可。因为实际调入时传入的是单个对象 obj。
argument type mismatch
相关文章推荐
- nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
- java.lang.IllegalArgumentException: object is not an instance of declaring class
- java.lang.IllegalArgumentException: object is not an instance of declaring class
- HIbernate 3.2 java.lang.IllegalArgumentException: object is not an instance of declaring class
- 使用反射报异常:object is not an instance of declaring class解决方案
- object is not an instance of declaring class while invoking public abstract…的解决
- 项目启动后,访问报 object is not an instance of declaring class 错误
- object is not an instance of declaring class 反射异常
- object is not an instance of declaring class 反射异常
- 异常笔记(2)--object is not an instance of declaring class while invoking public abstract java.lang.Long
- spring的 object is not an instance of declaring class
- 反射获取方法时:object is not an instance of declaring class
- 报错:object is not an instance of declaring class
- java axis调用cxf 的坑object is not an instance of declaring class while invoking public
- hibernate 4 object is not an instance of declaring class
- object is not an instance of declaring class
- java反射错误:object is not an instance of declaring class
- Xfile 错误记录 object is not an instance of declaring class
- object is not an instance of declaring class
- How to solve 'object of abstract class type "newFoo" is not allowed'?