I have that class:

```
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");
    }
}

```

And i call run method by reflection using:

```
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);
}

```

but i get:

```
java.lang.NoSuchMethodException: <init> [class android.content.Context]
at java.lang.Class.getConstructor0(Class.java:2320)
at java.lang.Class.getConstructor(Class.java:1725)

```

what i'm doing wrong? the constructor is obviously there

**UPDATE:**

Testing with:

```
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);
    }
}

```

But i get the same error:

```
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

```

Weird .... :(

I can't understand how it can find the class but it can't read the constructor.

I'm cleaning all the references to previous code before build again:

```
find out/ -name *OmniBrain* -exec rm -rf {} +

```
['https://Stackoverflow.com/questions/51011048', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1382894/']
1. Because cm are too big. You'd have to work with floats, which means you'd need to round all the time. They wanted something smaller. Also, the first devices were 160 dpi, do 1dp=1px which was convenient at the time (now very few devices ship at mdpi so this advantage is gone). It also just so happens to match the dpi of the iphone, rounded to the nearest 10 (iphone was 163 dpi), so measurements were what mobile devs were used to making easy conversions.
2. Its based on the physical dimensions. There can be some discrepancy, but in practice there isn't. If you have an image that is a little too small, the amount of distortion you get from stretching the tiny amount is negligible. The other major use of dp is in padding, and there the slight rounding errors are unnoticable as long as you're consistent on a single device.
1. As said by @Gabe Sechan, cm are too big (even mm). Contrary to cm, conversion to pixels is based on density category rather than exact density of the screen, which avoids rounding issues you'd have with cm to px (factor of 1.5x, 2x, 3x, etc rounds much better than an "arbitrary" ppi).
2. Yes. Conversion of dp to px is based on the density bucket the screen belongs to (mdpi, hdpi, xhdpi, etc) rather than the exact physical ppi. Bitmap graphics of an app are categorized by buckets, so for measurement consistency the dp is converted based on the density bucket rather than the real ppi. The drawback is that unlike a unit such as cm, the measurements are not guaranteed to be the same physical size on every screen ([example of such inconsistency)](https://stackoverflow.com/questions/9906520/android-which-ui-element-size-unit-to-use-if-dp-not-working/22713840).

References:

[Why aren't standard physical length units like mm used for touch UI layout?](https://stackoverflow.com/questions/19526525/why-arent-standard-physical-length-units-like-mm-used-for-touch-ui-layout)

[Why “dp-to-pixel” ratio changes with the screen density, but not necessarily in direct proportion](https://stackoverflow.com/questions/9907842/why-dp-to-pixel-ratio-changes-with-the-screen-density-but-not-necessarily-in)