Android反射方法错误 [英] Android Reflection Method Error
本文介绍了Android反射方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用这个Android类找出Reflection:
I'm trying to figure out Reflection with this Android class:
Class<?> c = Class.forName("com.android.internal.widget.LockPatternUtils");
Method method = c.getDeclaredMethod("getKeyguardStoredPasswordQuality");
method.setAccessible(true);
Object object = method.invoke(c); // Error with this line
result = object.toString());
方法 getKeyguardStoredPasswordQuality
被声明为(否)参数):
The method getKeyguardStoredPasswordQuality
is declared as (no parameters):
public int getKeyguardStoredPasswordQuality() {
// codes here
}
我得到的错误是:
Exception: java.lang.IllegalArgumentException: expected receiver of type com.android.internal.widget.LockPatternUtils, but got java.lang.Class<com.android.internal.widget.LockPatternUtils>
如何声明 com.android.internal.widget.LockPatternUtils
作为接收者?
推荐答案
您正在传递类
到 #invoke()
而不是 LockPatternUtils
的实例。
You are passing the class
to #invoke()
instead of an instance of LockPatternUtils
.
您可以使用 #newInstance()
。
You can create an instance using #newInstance()
.
这篇关于Android反射方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文