0
在配置活动内我有两个控件调用相同的方法。这里是方法:启动意图内部方法运行通过反射
public void goDetection() {
Intent detection = new Intent(this, Detection.class);
startActivity(detection);
}
该方法是从一个基本的按钮单击执行,它工作正常。 同样的方法也应该在AlertDialog内部执行,与“positiveButton”相关的方法。 我调用该方法的 “positiveButton” 的处理程序的onClick因为这:
try {
Method method = Configuration.class.getMethod(methodPositive);
Object obj = new Configuration();
method.invoke(obj);
} catch (NoSuchMethodException e) {
Log.d("There is an error in Configuration class: NoSuchMethodException", e.getMessage());
} catch (IllegalAccessException e) {
Log.d("There is an error in Configuration class: IllegalAccessException", e.getMessage());
} catch (IllegalArgumentException e) {
Log.d("There is an error in Configuration class: IllegalArgumentException", e.getMessage());
} catch (InvocationTargetException e) {
Log.d("There is an error in Configuration class: InvocationTargetException", e.getMessage());
}
其中methodPositive = “goDetection”。 使用中我发现这个方法的获取开始goDetection()方法Log.d()插入,但执行
startActivity(detection);
语句时出现错误。从logcat的第一应用代码相关的错误是:在上面的语句“NullPointerException异常的println需要一个消息”:
catch (InvocationTargetException e) {
Log.d("There is an error in Configuration class: InvocationTargetException", e.getMessage());
}
这不是我第一次使用这个机制,但它是第一次我会被卡住。我错过了什么? 非常感谢!
需要更多代码。在某处打印或记录未设置的输入值。 – r2DoesInc
我没有打印任何东西,我记录的唯一值是在捕获部分,所有e.getMessage() –
错误,“NullPointerException:println需要一条消息” – r2DoesInc