Example usage for java.lang NoSuchMethodException toString

List of usage examples for java.lang NoSuchMethodException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static void main(String[] args) {

    Main cls = new Main();
    Class c = cls.getClass();/*from   w  w  w.ja  v  a  2  s  .c  o  m*/

    try {
        Method m = c.getDeclaredMethod("show", null);
        System.out.println("method = " + m.toString());

        // method Integer
        Class[] cArg = new Class[1];
        cArg[0] = Integer.class;
        Method lMethod = c.getDeclaredMethod("showInteger", cArg);
        System.out.println("method = " + lMethod.toString());
    } catch (NoSuchMethodException e) {
        System.out.println(e.toString());
    }
}

From source file:me.yyam.beanutils.BeanUtilEx.java

/**
 * IntrospectorPropertyDescriptor Bean --> Map
 * @param obj//from   www. j  av  a 2s  .com
 * @return
 */
public static Map transBean2Map(Object obj) throws Exception {
    if (obj == null) {
        return null;
    }
    Map<String, Object> map = new HashMap<>();
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(obj);
    for (PropertyDescriptor property : propertyDescriptors) {
        String key = property.getName();
        if (!key.equals("class")) {
            try {
                Object value = PropertyUtils.getProperty(obj, key);
                if (value == null) {
                    map.put(key, value);
                } else {
                    if (value instanceof List) {
                        List list = new ArrayList();
                        for (Object v : (List) value) {
                            list.add(transBean2Map(v));
                        }
                        map.put(key, list);
                    } else {
                        if (value instanceof Enum) {
                            value = value.toString();
                        }
                        if (isPrimitive(value)) {
                            map.put(key, value);
                        } else {
                            Map cmap = transBean2Map(value);
                            map.put(key, cmap);
                        }
                    }
                }
            } catch (NoSuchMethodException e) {
                System.out.println(e.toString());
            }
        }
    }
    return map;
}

From source file:uk.co.modularaudio.util.hibernate.ReflectionUtils.java

public static void copyOverGetAttributes(final Class<?> interfaceListingAttributes, final Object src,
        final Object dest) throws DatastoreException {
    try {/*from   ww  w . jav a  2s .co  m*/
        final Method methods[] = interfaceListingAttributes.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final Method getMethod = methods[i];
            final String methodName = getMethod.getName();

            if (methodName.startsWith("get")) {
                final Class<?> returnType = getMethod.getReturnType();

                final Object result = getMethod.invoke(src);

                final String setMethodName = methodName.replaceFirst("get", "set");

                final Method setMethod = interfaceListingAttributes.getDeclaredMethod(setMethodName,
                        new Class[] { returnType });

                setMethod.invoke(dest, result);
            }
        }
    } catch (final IllegalAccessException iae) {
        throw new DatastoreException("iae: " + iae.toString());
    } catch (final InvocationTargetException ite) {
        throw new DatastoreException("ite: " + ite.toString());
    } catch (final NoSuchMethodException nsme) {
        throw new DatastoreException("nsme: " + nsme.toString());
    }
}

From source file:com.master.metehan.filtereagle.Util.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";

    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/')
            .append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n");

    int dataSubId;
    try {/*  w  w w.  j av  a 2 s  . c om*/
        dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
    } catch (Throwable ignored) {
        dataSubId = -1;
    }

    Method getNetworkCountryIso = null;
    Method getNetworkOperator = null;
    Method getNetworkOperatorName = null;
    Method getDataEnabled = null;
    try {
        getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription", int.class);
        getNetworkOperator = tm.getClass().getMethod("getNetworkOperatorForSubscription", int.class);
        getNetworkOperatorName = tm.getClass().getMethod("getNetworkOperatorName", int.class);
        getDataEnabled = tm.getClass().getMethod("getDataEnabled", int.class);

        getNetworkCountryIso.setAccessible(true);
        getNetworkOperator.setAccessible(true);
        getNetworkOperatorName.setAccessible(true);
        getDataEnabled.setAccessible(true);
    } catch (NoSuchMethodException ex) {
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions) {
            sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId())
                    .append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc())
                    .append(' ').append(si.getCarrierName())
                    .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append(si.getSubscriptionId() == dataSubId ? " *" : "").append("\r\n");
            if (getNetworkCountryIso != null && getNetworkOperator != null && getNetworkOperatorName != null
                    && getDataEnabled != null)
                try {
                    sb.append("Network ").append(si.getSimSlotIndex() + 1).append('/')
                            .append(si.getSubscriptionId()).append(' ')
                            .append(getNetworkCountryIso.invoke(tm, si.getSubscriptionId())).append('/')
                            .append(getNetworkOperator.invoke(tm, si.getSubscriptionId())).append(' ')
                            .append(getNetworkOperatorName.invoke(tm, si.getSubscriptionId()))
                            .append(sm.isNetworkRoaming(si.getSubscriptionId()) ? " R" : "").append(' ')
                            .append(String.format("%B", getDataEnabled.invoke(tm, si.getSubscriptionId())))
                            .append("\r\n");
                } catch (IllegalAccessException | InvocationTargetException ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:ProxyFactory.java

private synchronized Constructor getConstructor() {
    Constructor ctor = ctorRef == null ? null : (Constructor) ctorRef.get();

    if (ctor == null) {
        try {//w  w w  . ja v  a  2  s .  co m
            ctor = Proxy.getProxyClass(getClass().getClassLoader(), interfaces)
                    .getConstructor(new Class[] { InvocationHandler.class });
        } catch (NoSuchMethodException e) {
            throw new InternalError(e.toString());
        }

        ctorRef = new SoftReference(ctor);
    }

    return ctor;
}

From source file:run.ace.IncomingMessages.java

public static Object create(JSONArray message, Activity activity) throws JSONException {
    String fullTypeName = message.getString(2);
    Class c = null;/*from w w  w  .j  a v  a 2s  .  c o  m*/
    Object instance = null;
    try {
        c = Class.forName(fullTypeName);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Unable to find a class named '" + fullTypeName + "'");
    }

    if (message.length() == 4) {
        // Parameterized constructor
        JSONArray constructorArgs = message.getJSONArray(3);
        Object[] args = Utils.convertJSONArrayToArray(constructorArgs);
        instance = Utils.invokeConstructorWithBestParameterMatch(c, args);
    } else {
        // Default constructor
        try {
            // Expect the Context constructor
            try {
                instance = c.getConstructor(new Class[] { Context.class }).newInstance(activity);
            } catch (NoSuchMethodException ex) {
                // Try the default constructor instead
                instance = c.getConstructor().newInstance();
            }
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException(fullTypeName
                    + " does not have a public default constructor, or a public constructor with a single Context parameter");
        } catch (InvocationTargetException ex) {
            throw new RuntimeException(
                    "Error in " + fullTypeName + " constructor: " + ex.getTargetException().toString());
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(fullTypeName + ", or its relevant constructor, isn't public");
        } catch (InstantiationException ex) {
            throw new RuntimeException("Error instantiating " + fullTypeName + ": " + ex.toString());
        }
    }

    return instance;
}

From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveEnum.java

@Override
public Object getObject(Class<?> type, String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }//w ww .j  a  v  a2s  .  co  m

    // discover the fromValue Method
    try {
        Method valueOfMethod = type.getMethod("fromValue", new Class[] { String.class });
        return valueOfMethod.invoke(null, new Object[] { value });

    } catch (NoSuchMethodException e) {
        // do nothing, check valueOf method
    } catch (IllegalArgumentException e) {
        throw new IllegalStateException(e.toString());
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e.toString());
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof RuntimeException) {
            throw (RuntimeException) e.getTargetException();
        }
    }

    // backwards compability, check valueOf method to support
    // "simple" enums without value object
    try {
        Method valueOfMethod = type.getMethod("valueOf", new Class[] { String.class });
        return valueOfMethod.invoke(null, new Object[] { value });

    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e.toString());
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof RuntimeException) {
            throw (RuntimeException) e.getTargetException();
        }
    } catch (NoSuchMethodException e) {
        String err = type.getName() + " does not contain the required method: public static " + type.getName()
                + " valueOf(String);";
        throw new IllegalArgumentException(err);
    }

    return value;
}

From source file:com.parrot.cyclops.CameraView.java

private void initCameraView(Context context) {
    if (DEBUG)/*from ww  w  .j  ava  2s.c om*/
        Log.d(TAG, "initCameraView");
    mContext = context;
    getHolder().addCallback(mSHCallback);
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    // Use reflection to call a hidden method of SurfaceView added by Parrot.
    Class<?> params[] = new Class[1];
    params[0] = String.class;
    try {
        mSetTitleMethod = getClass().getSuperclass().getDeclaredMethod("setTitle", params);
    } catch (NoSuchMethodException e) {
        Log.e(TAG, e.toString());
        mSetTitleMethod = null;
    }
}

From source file:com.ewcms.publication.freemarker.directive.PropertyDirective.java

/**
 * /* w ww  . ja  va 2s  . c  o  m*/
 * 
 * @param objectValue
 *                
 * @param property 
 *                ??
 * @return           
 */
protected Object getValue(Object objectValue, String property) throws NoSuchMethodException {
    try {
        return PropertyUtils.getProperty(objectValue, property);
    } catch (NoSuchMethodException e) {
        throw e;
    } catch (Exception e) {
        throw new NoSuchMethodException(e.toString());
    }
}

From source file:com.ewcms.publication.freemarker.directive.PropertyDirective.java

@Override
@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {

    String propertyName = getPropertyName(env, params);
    Object objectValue = getObjectValue(env, params);

    if (EmptyUtil.isNull(propertyName)) {
        logger.error("\"name\" parameter must set");
        throw new TemplateModelException("\"name\" parameter must set");
    }//from w w  w  . j a  va 2s . co  m

    try {
        if (EmptyUtil.isArrayNotEmpty(loopVars)) {
            Object value = loopValue(objectValue, propertyName, env, params);
            if (EmptyUtil.isNotNull(value)) {
                loopVars[0] = env.getObjectWrapper().wrap(value);
                if (EmptyUtil.isNull(body)) {
                    logger.warn("body is empty");
                } else {
                    body.render(env.getOut());
                }
            }
        } else if (EmptyUtil.isNotNull(body)) {
            Object value = loopValue(objectValue, propertyName, env, params);
            if (EmptyUtil.isNotNull(value)) {
                FreemarkerUtil.setVariable(env, defaultLoop, value);
                body.render(env.getOut());
                FreemarkerUtil.removeVariable(env, defaultLoop);
            }
        } else {
            String outValue = constructOut(objectValue, propertyName, env, params);
            if (EmptyUtil.isNotNull(outValue)) {
                Writer out = env.getOut();
                out.write(outValue.toString());
                out.flush();
            }
        }
    } catch (NoSuchMethodException e) {
        Writer out = env.getOut();
        out.write(e.toString());
        out.flush();
        throw new TemplateModelException(e.getMessage());
    }
}