У меня есть этот класс:
public class DNDRunner {
private NotificationManager mNoMan;
public DNDRunner(Context context) {
mNoMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
public void run(String param) {
mNoMan.setZenMode(Integer.parseInt(param), null, "DNDRunner");
}
}
И я вызываю метод run по отражению, используя:
try {
Class mRunner = Class.forName(runner);
Constructor constructor = mRunner.getConstructor(new Class[]{Context.class});
Object object = constructor.newInstance(new Object[]{mContext});
Method run = mRunner.getMethod("run", new Class[]{String.class});
run.invoke(object, new Object[]{value});
} catch (Exception e) {
Log.e(TAG, "Runner", e);
}
но я получаю:
java.lang.NoSuchMethodException: <init> [class android.content.Context]
at java.lang.Class.getConstructor0(Class.java:2320)
at java.lang.Class.getConstructor(Class.java:1725)
что я делаю не так? конструктор явно там
UPDATE:
Тестирование с:
private void executeRunner() {
try {
Class mRunner = Class.forName(runner);
Constructor<?> constructor = mRunner.getDeclaredConstructor(Context.class);
Log.d(TAG, "Is public constructor? " + Modifier.isPublic(constructor.getModifiers()));
Object object = constructor.newInstance(mContext);
Method run = mRunner.getDeclaredMethod("run", String.class);
run.invoke(object, value);
} catch (Exception e) {
Log.e(TAG, "Runner", e);
}
}
Но я получаю ту же ошибку:
06-25 20:24:44.703 2420 2420 E OmniAction: Runner
06-25 20:24:44.703 2420 2420 E OmniAction: java.lang.NoSuchMethodException: <init> [class android.content.Context]
06-25 20:24:44.703 2420 2420 E OmniAction: at java.lang.Class.getConstructor0(Class.java:2320)
06-25 20:24:44.703 2420 2420 E OmniAction: at java.lang.Class.getDeclaredConstructor(Class.java:2166)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnilib.actions.OmniAction.executeRunner(OmniAction.java:148)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnilib.actions.OmniAction.execute(OmniAction.java:89)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnibrain.EventService.execOmniActions(EventService.java:302)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnibrain.EventService.execOnConnectActions(EventService.java:257)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnibrain.EventService.-wrap5(Unknown Source:0)
06-25 20:24:44.703 2420 2420 E OmniAction: at org.omnirom.omnibrain.EventService$2.onReceive(EventService.java:189)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1313)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.os.Handler.handleCallback(Handler.java:790)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.os.Looper.loop(Looper.java:164)
06-25 20:24:44.703 2420 2420 E OmniAction: at android.app.ActivityThread.main(ActivityThread.java:6499)
06-25 20:24:44.703 2420 2420 E OmniAction: at java.lang.reflect.Method.invoke(Native Method)
06-25 20:24:44.703 2420 2420 E OmniAction: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
06-25 20:24:44.703 2420 2420 E OmniAction: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
06-25 20:24:44.705 1692 1697 I zygote64: Do full code cache collection, code=507KB, data=308KB
Странно ....: (
Я не могу понять, как он может найти класс, но он не может прочитать конструктор.
Я очищаю все ссылки на предыдущий код перед повторной сборкой:
find out/ -name *OmniBrain* -exec rm -rf {} +