I can not figure out what I am doing wrong. I have 2 methods, this one which works:
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){}
}
}
then this one which doesn’t work:
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();
}
}
}
On this line (in the second method):
Object returnVal = adjust.getMethod("isSeekBar").invoke(whatInstance);
when It gets here, it just skips over my if statement and goes directly to the closing brace of the method. What is causing that? Here is the method that is being called:
public boolean isSeekBar(){
return true;
}
I am assuming that it is throwing an error, but none of the catch statements are catching one. I am now stumped…
You can try catching the more generic Throwable – if this function is executed in the UI thread you will not see the exception.
in any case,
if(returnVal == true){does not compile (Incompatible operand types Object and boolean)Use
if (returnVal.equals(true)) {