我无法弄清楚我做错了什么。我有两种方法,这一种有效:
protected void applySelection(String adjustment, String action){
if(!adjustment.equals("") || !action.equals("")){
try{
ClassLoader myClassLoader = this.getClass().getClassLoader();
String myPackage = this.getClass().getPackage().getName();
String classNameToBeLoaded = myPackage + "." + action + "." + adjustment;
Class adjust = myClassLoader.loadClass(classNameToBeLoaded);
Object whatInstance = adjust.newInstance();
adjust.getMethod("setBitmap", new Class[]{Bitmap.class}).invoke(whatInstance, new Object[]{this.stage.getImage()});
Bitmap bmp = (Bitmap)adjust.getMethod("applyFilter").invoke(whatInstance);
if(bmp != null){
Edit.this.stage.setStageImage(bmp);
Edit.this.stage.showTopItems(bmp);
}
}catch(IllegalArgumentException e){
}catch(IllegalAccessException e){
}catch(InvocationTargetException e){
}catch(Exception e){}
}
}
然后这个不起作用:
protected void setFromSlider(String adjustment, String action){
if(!adjustment.equals("") || !action.equals("")){
try{
ClassLoader myClassLoader = this.getClass().getClassLoader();
String myPackage = this.getClass().getPackage().getName();
String classNameToBeLoaded = myPackage + "." + action + "." + adjustment;
Class adjust = myClassLoader.loadClass(classNameToBeLoaded);
Object whatInstance = adjust.newInstance();
Object returnVal = adjust.getMethod("isSeekBar").invoke(whatInstance);
if(returnVal == true){
// Do something
}else{
// Do something else
}
}catch(NullPointerException e){
e.getMessage();
}catch(IllegalArgumentException e){
e.getMessage();
}catch(IllegalAccessException e){
e.getMessage();
}catch(Exception e){
e.getMessage();
}
}
}
在这条线上(在第二种方法中):
Object returnVal = adjust.getMethod("isSeekBar").invoke(whatInstance);
当它到达这里时,它只是跳过我的 if 语句并直接转到方法的右括号。是什么原因造成的?这是被调用的方法:
public boolean isSeekBar(){
return true;
}
我假设它正在抛出一个错误,但没有一个 catch 语句正在捕获一个错误。我现在被难住了……