Call a method in the current class based on its name. Note that the function being called must be public. Inside the PDE, 'public' is automatically added, but when used without the preprocessor, (like from Eclipse) you'll have to do it yourself.
(String name)
| 3862 | * (like from Eclipse) you'll have to do it yourself. |
| 3863 | */ |
| 3864 | public void method(String name) { |
| 3865 | try { |
| 3866 | Method method = getClass().getMethod(name, new Class[] {}); |
| 3867 | method.invoke(this, new Object[] { }); |
| 3868 | |
| 3869 | } catch (IllegalArgumentException e) { |
| 3870 | e.printStackTrace(); |
| 3871 | } catch (IllegalAccessException e) { |
| 3872 | e.printStackTrace(); |
| 3873 | } catch (InvocationTargetException e) { |
| 3874 | e.getTargetException().printStackTrace(); |
| 3875 | } catch (NoSuchMethodException nsme) { |
| 3876 | System.err.println("There is no public " + name + "() method " + |
| 3877 | "in the class " + getClass().getName()); |
| 3878 | } catch (Exception e) { |
| 3879 | e.printStackTrace(); |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | |
| 3884 | /** |
no test coverage detected