Example usage for java.lang NoSuchMethodException printStackTrace

List of usage examples for java.lang NoSuchMethodException printStackTrace

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

/**
 * Get the cookie of an asset using an undocumented API call that is marked
 * as "no to be used by applications" in its source code
 * /*from  ww  w  . j a v a2  s  .  com*/
 * @see <a href="http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/android/content/res/AssetManager.java#612">AssetManager.java#612</a>
 * @return the cookie
 */
private static int addAssets(final File APKFILE, final Object ASSETMANAGERINSTANCE) {
    try {
        Method addAssetPath = ASSETMANAGERINSTANCE.getClass().getMethod("addAssetPath",
                new Class[] { String.class });
        return (Integer) addAssetPath.invoke(ASSETMANAGERINSTANCE, APKFILE.getAbsolutePath());
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return -1;
}

From source file:Main.java

private static boolean isWifiApEnabled(WifiManager wifiManager) {
    try {//ww  w  . ja  va  2 s .  co  m
        Method method = wifiManager.getClass().getMethod("isWifiApEnabled");
        method.setAccessible(true);
        return (Boolean) method.invoke(wifiManager);

    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static ArrayList<ParcelUuid> getDeviceUuids(BluetoothDevice device) {
    ArrayList<ParcelUuid> result = new ArrayList<ParcelUuid>();

    try {/*w ww  .  j  a va2  s .  c om*/
        Method method = device.getClass().getMethod("getUuids", null);
        ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(device, null);
        if (phoneUuids != null) {
            for (ParcelUuid uuid : phoneUuids) {
                if (D)
                    Log.d(TAG, device.getName() + ": " + uuid.toString());
                result.add(uuid);
            }
        }
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    }

    return result;
}

From source file:Main.java

public static void forceStopPackage(Context ctx, String packageName) {

    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

    Method method;//from   w  ww .j  av a2 s.co m
    try {
        method = Class.forName("android.app.ActivityManager").getMethod("forceStopPackage", String.class);
        method.invoke(am, packageName);
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * switch data to on/off//from   w ww  .  j a  v a2s .c  om
 * 
 * @param context
 * @param status
 */
public static void setData(Context context, boolean status) {
    ConnectivityManager dataManager;
    dataManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Method dataMtd = null;
    try {
        dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    dataMtd.setAccessible(true);
    try {
        dataMtd.invoke(dataManager, status);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

private static void setBitmap(BitmapDrawable drawable, Bitmap bitmap) {
    try {//w ww.j av  a  2 s.  c  o m
        Method method = getMethod(BitmapDrawable.class, "setBitmap", new Class[] { Bitmap.class });
        if (method != null) {
            method.setAccessible(true);
            method.invoke(drawable, bitmap);
        }
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

private static void closeWifiAp(WifiManager wifiManager) {
    if (isWifiApEnabled(wifiManager)) {
        try {/*www. java2 s .  co  m*/
            Method method = wifiManager.getClass().getMethod("getWifiApConfiguration");
            method.setAccessible(true);

            WifiConfiguration config = (WifiConfiguration) method.invoke(wifiManager);

            Method method2 = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,
                    boolean.class);
            method2.invoke(wifiManager, config, false);
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void putTextToViewById(Activity a, int id, int text) {

    View view = a.findViewById(id);

    Method m = null;//from  w ww .j av  a 2  s  .c  om

    try {
        m = view.getClass().getMethod("setText", new Class[] { Integer.TYPE });
    } catch (NoSuchMethodException e) {

    }
    if (m != null) {
        try {
            m.invoke(view, text);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:ypcnv.helpers.EnumHelper.java

/**
 * A method to get a list of a string representations with object's possible
 * values./*from w  w  w.  ja  v  a 2 s  . com*/
 */
public static <T extends Enum<T>> List<String> toStringList(Class<T> target) {
    String wantedMethodName = "getDisplayValue";
    List<String> list = new LinkedList<String>();
    Method wantedMethodValue = null;

    try {
        wantedMethodValue = target.getMethod(wantedMethodName);
    } catch (NoSuchMethodException e) {
        LOG.error("method '" + wantedMethodName + "' is not implemented in '" + target + "'.");
        e.printStackTrace();
    }

    for (Object obj : target.getEnumConstants()) {
        if (wantedMethodValue == null) {
            list.add(obj.toString());
        } else {
            try {
                list.add((String) wantedMethodValue.invoke(obj));
            } catch (Exception e) {
                LOG.error("Failed to create list of possible values.");
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
    }

    return list;
}

From source file:info.aamulumi.sharedshopping.APIConnection.java

/**
 * Send a HTTP request and parse the returned element.
 * The JSONObject returned by server must have :
 * - success : int - 1 if request is successful
 * - data : JSONObject - element which will be parsed
 *
 * @param url            - url to access
 * @param method         - HTTP method (GET, PUT, ...)
 * @param parseMethod    - name of the method used to parse an object in data
 * @param urlParameters  - parameters send in URL
 * @param bodyParameters - parameters send in body (encoded)
 * @return the list of parsed elements//from   ww  w .  ja v  a  2s .  c om
 */
@SuppressWarnings("unchecked")
private static <T> T doHTTPRequestAndParse(String url, String method, String parseMethod,
        HashMap<String, String> urlParameters, HashMap<String, String> bodyParameters) {
    // Get parseMethod
    Class<?>[] cArg = new Class[1];
    cArg[0] = JSONObject.class;

    Method parse;
    try {
        parse = APIConnection.class.getMethod(parseMethod, cArg);
    } catch (NoSuchMethodException e1) {
        e1.printStackTrace();
        return null;
    }

    // Do the request
    JSONObject json = makeHttpRequest(url, method, urlParameters, bodyParameters);

    if (json == null)
        return null;
    try {
        int success = json.getInt("success");
        // Parse if successful
        if (success == 1) {
            return (T) parse.invoke(APIConnection.class, json.getJSONObject("data"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return null;
}