private String getMethod() {
// TestR test = new TestR();
Class ct;
String str = "";
Object in = null;
try {
ct = Class.forName("com.example.speaker.TestR");
try {
in = ct.newInstance();
} catch (InstantiationException e1) {
Log.i("TestR", "InstantiationException");
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
try {
Method mt1 = ct.getDeclaredMethod("setStr", String.class);
Method mt2 = ct.getDeclaredMethod("getStr", null);
mt1.setAccessible(true);
try {
mt1.invoke(in, "Hello invoke");
str = (String) mt2.invoke(in, null);
} catch (IllegalArgumentException e) {
Log.i("TestR", "IllegalArgumentException");
} catch (IllegalAccessException e) {
Log.i("TestR", "IllegalAccessException");
} catch (InvocationTargetException e) {
Log.i("TestR", "InvocationTargetException");
}
} catch (SecurityException e) {
Log.i("TestR", "SecurityException");
} catch (NoSuchMethodException e) {
Log.i("TestR", "NoSuchMethodException");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
Log.i("TestR", "ClassNotFoundException");
}
return str;
// TestR test = new TestR();
Class ct;
String str = "";
Object in = null;
try {
ct = Class.forName("com.example.speaker.TestR");
try {
in = ct.newInstance();
} catch (InstantiationException e1) {
Log.i("TestR", "InstantiationException");
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
try {
Method mt1 = ct.getDeclaredMethod("setStr", String.class);
Method mt2 = ct.getDeclaredMethod("getStr", null);
mt1.setAccessible(true);
try {
mt1.invoke(in, "Hello invoke");
str = (String) mt2.invoke(in, null);
} catch (IllegalArgumentException e) {
Log.i("TestR", "IllegalArgumentException");
} catch (IllegalAccessException e) {
Log.i("TestR", "IllegalAccessException");
} catch (InvocationTargetException e) {
Log.i("TestR", "InvocationTargetException");
}
} catch (SecurityException e) {
Log.i("TestR", "SecurityException");
} catch (NoSuchMethodException e) {
Log.i("TestR", "NoSuchMethodException");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
Log.i("TestR", "ClassNotFoundException");
}
return str;
}
package com.example.speaker;
public class TestR {
public TestR () {
this.str = "This is TestR";
}
private String str = "";
protected void setStr(String str) {
this.str = str;
}
protected String getStr() {
return this.str;
}
}