问题描述
我要检查,如果该方法 Camera.Parameters.getHorizontalViewAngle()
设备上存在(它只能从API 8和我分SDK API是7)。我试图用反思,作为解释 rel=\"nofollow\">,但它捕获一个错误说参数的数目是错误的:
java.lang.IllegalArgumentException异常:错误的参数个数
摄像头摄像头;
相机= Camera.open();
参数PARAMS = camera.getParameters();
方法M = Camera.Parameters.class.getMethod(getHorizontalViewAngle,新的Class [] {});
浮HVA = 0;
尝试{
m.invoke(参数,可以HVA);
}赶上(抛出:IllegalArgumentException五){
// TODO自动生成catch块
e.printStackTrace();
}赶上(IllegalAccessException E){
// TODO自动生成catch块
e.printStackTrace();
}赶上(的InvocationTargetException E){
// TODO自动生成catch块
e.printStackTrace();
}
m.invoke(参数,可以HVA);
应
m.invoke(参数,可以为null);
Camera.Parameters.getHorizontalViewAngle()
不带任何参数和上面的线有争论HVA。如果您正在寻找返回变量做 HVA = m.invoke(参数,可以为null);
I want to check if the method Camera.Parameters.getHorizontalViewAngle()
exists on the device (it's only available from API 8 and my min SDK API is 7). I tried to use "reflection", as explained here, but it catches an error saying the number of arguments is wrong:
java.lang.IllegalArgumentException: wrong number of arguments
Anybody could help?
Camera camera;
camera = Camera.open();
Parameters params = camera.getParameters();
Method m = Camera.Parameters.class.getMethod("getHorizontalViewAngle", new Class[] {} );
float hVA = 0;
try {
m.invoke(params, hVA);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m.invoke(params, hVA);
should be
m.invoke(params, null);
Camera.Parameters.getHorizontalViewAngle()
doesn't take any arguments and the above line has the argument hVA. If you're looking for the return variable do hVA = m.invoke(params, null);
这篇关于检查的方法是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!