getting java.lang.reflect.InvocationTargetException while adding a button to layout

From the error I’m assuming you’re using JavaFX 11 (or at least JavaFX 9+). Note that the ultimate problem is not the InvocationTargetException but the IllegalAccessError: Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0x46b3f4cf) cannot access class com.sun.javafx.scene.layout.RegionHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene.layout to unnamed … Read more

Enable/disable data connection in android programmatically

This code sample should work for android phones running gingerbread and higher: private void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final Class conmanClass = Class.forName(conman.getClass().getName()); final Field connectivityManagerField = conmanClass.getDeclaredField(“mService”); connectivityManagerField.setAccessible(true); final Object connectivityManager = connectivityManagerField.get(conman); final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod … Read more