Example usage for java.lang NoSuchFieldException getMessage

List of usage examples for java.lang NoSuchFieldException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchFieldException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

static Field getField(Class<?> clz, final String fldName) {
    if (clz == null || TextUtils.isEmpty(fldName)) {
        return null;
    }//from ww  w  .  j  a v  a2  s . co  m
    Field fld = null;
    try {
        fld = clz.getDeclaredField(fldName);
        fld.setAccessible(true);
    } catch (NoSuchFieldException e) {
        Log.d(TAG, e.getMessage(), e);
    }
    return fld;
}

From source file:Main.java

public static boolean replaceField(String className, String fieldName, Object desObj, Object fieldObj) {
    Field tempField;//  w  w w.j a  v a2  s.co  m
    try {
        tempField = Class.forName(className).getDeclaredField(fieldName);
        tempField.setAccessible(true);
        tempField.set(desObj, fieldObj);
        return true;
    } catch (NoSuchFieldException e) {
        // TODO Auto-generated catch block
        Log.i("DEX", "" + e.getMessage());
        // 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();
    }
    return false;
}

From source file:com.github.pjungermann.config.types.DefaultConfigFactorySelectorTest.java

@SuppressWarnings("unchecked")
static Collection<ConfigFactory> getConfigFactories(DefaultConfigFactorySelector selector) {
    try {/*ww  w .  jav a  2 s  .c  o  m*/
        Field listField = DefaultConfigFactorySelector.class.getDeclaredField("configFactories");
        listField.setAccessible(true);
        return (Collection<ConfigFactory>) listField.get(selector);

    } catch (NoSuchFieldException e) {
        fail("field not found: " + e.getMessage());

    } catch (IllegalAccessException e) {
        fail("field was not accessible: " + e.getMessage());
    }

    return null;
}

From source file:com.genentech.chemistry.tool.sdfAggregator.SDFAggregator.java

/**
 * Generates help string of all aggregator functions
 *
 *///from w  ww  .  j  a  va  2 s . c  o  m
private static String getAggregationFunctionDescriptions() {
    StringBuilder sb = new StringBuilder(2000);
    String desc = "";

    for (String funcName : functionArr) {
        try {
            desc = (String) Class.forName(PACKAGEName + "." + funcName).getField("DESCRIPTION").get(null);
        } catch (NoSuchFieldException e) {
            System.err.println(e.getMessage());
            System.err.printf("Aggregation function %s does not implement DESCRIPION", funcName);
            exitWithHelp(options);
        } catch (IllegalAccessException e) {
            System.err.println(e.getMessage());
            System.err.println("Function does not exist: " + funcName);
            exitWithHelp(options);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.err.println(e.getMessage());
            System.err.println("Function does not exist: " + funcName);
            exitWithHelp(options);
        }

        sb.append(desc);
    }
    return sb.toString();
}

From source file:org.apache.pulsar.common.configuration.PulsarConfigurationLoader.java

/**
 * Converts a PulsarConfiguration object to a ServiceConfiguration object.
 *
 * @param conf/*from  ww  w.j  a va  2  s .  co m*/
 * @param ignoreNonExistMember
 * @return
 * @throws IllegalArgumentException
 *             if conf has the field whose name is not contained in ServiceConfiguration and ignoreNonExistMember is false.
 * @throws RuntimeException
 */
public static ServiceConfiguration convertFrom(PulsarConfiguration conf, boolean ignoreNonExistMember)
        throws RuntimeException {
    try {
        final ServiceConfiguration convertedConf = ServiceConfiguration.class.newInstance();
        Field[] confFields = conf.getClass().getDeclaredFields();
        Arrays.stream(confFields).forEach(confField -> {
            try {
                Field convertedConfField = ServiceConfiguration.class.getDeclaredField(confField.getName());
                confField.setAccessible(true);
                if (!Modifier.isStatic(convertedConfField.getModifiers())) {
                    convertedConfField.setAccessible(true);
                    convertedConfField.set(convertedConf, confField.get(conf));
                }
            } catch (NoSuchFieldException e) {
                if (!ignoreNonExistMember) {
                    throw new IllegalArgumentException(
                            "Exception caused while converting configuration: " + e.getMessage());
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(
                        "Exception caused while converting configuration: " + e.getMessage());
            }
        });
        return convertedConf;
    } catch (InstantiationException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    }
}

From source file:de.micromata.genome.gwiki.utils.ClassUtils.java

public static void populateBeanWithPuplicMembers(Object bean, Map<String, Object> reqMap) {
    Class<?> cls = bean.getClass();
    for (Map.Entry<String, Object> me : reqMap.entrySet()) {
        try {/* w  w  w .ja v a 2  s  .  c  o m*/
            String s = getSetter(me.getKey());
            if (hasMethod(cls, s) == true) {
                BeanUtilsBean.getInstance().setProperty(bean, me.getKey(), me.getValue());
            } else {
                Field f;
                try {
                    f = cls.getField(me.getKey());
                    if (f != null) {
                        f.set(bean, convert(me.getValue(), f.getType()));
                    }
                } catch (NoSuchFieldException ex) {
                    continue;
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("Failure to set propert: " + me.getKey() + " in class: " + cls.getName()
                    + "; with value: " + me.getValue() + ";" + ex.getMessage(), ex);
        }
    }
}

From source file:com.ocs.dynamo.utils.ClassUtils.java

/**
 * Returns a field with a certain name from a class
 * /*from  w  w  w  .  j av a 2 s  . c  o m*/
 * @param clazz
 *            the class
 * @param fieldName
 *            the name of the filed
 * @return
 */
public static Field getField(Class<?> clazz, String fieldName) {
    Field field = null;
    if (clazz != null) {
        try {
            field = clazz.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            LOG.debug(e.getMessage(), e);
            if (clazz.getSuperclass() != null) {
                return getField(clazz.getSuperclass(), fieldName);
            }
        }
    }
    return field;
}

From source file:com.rockagen.commons.util.ClassUtil.java

/**
 * obtain field If recursively is true, obtain fields from all class
 * hierarchy//from  w w w.  jav a 2 s .  com
 * 
 * @param clazz class
 *            where fields are searching
 * @param fieldName
 *            field name
 * @param recursively
 *            param
 * @return list of fields
 */
public static Field getDeclaredField(Class<?> clazz, String fieldName, boolean recursively) {
    try {
        return clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && recursively) {
            return getDeclaredField(superClass, fieldName, true);
        }
    } catch (SecurityException e) {
        log.error("{}", e.getMessage(), e);
    }
    return null;

}

From source file:BrowserLauncher.java

/**
 * Called by a static initializer to load any classes, fields, and methods required at runtime
 * to locate the user's web browser.//from  w w w  .j  av a2s  .  c  o  m
 * @return <code>true</code> if all intialization succeeded
 *         <code>false</code> if any portion of the initialization failed
 */
private static boolean loadClasses() {
    switch (jvm) {
    case MRJ_2_0:
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");

            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(
                    new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });

            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class });
            putParameter = appleEventClass.getDeclaredMethod("putParameter",
                    new Class[] { int.class, aeDescClass });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});

            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_2_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
            Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
            kSystemFolderType = systemFolderField.get(null);
            findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
            getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
            getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (SecurityException se) {
            errorMessage = se.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_0:
        try {
            Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
            Constructor constructor = linker.getConstructor(new Class[] { Class.class });
            linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (InvocationTargetException ite) {
            errorMessage = ite.getMessage();
            return false;
        } catch (InstantiationException ie) {
            errorMessage = ie.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:org.kuali.rice.core.framework.persistence.jpa.metadata.MetadataManager.java

/**
 * Retrieves the primary key as an object for the given Object (which is assumed to be a JPA entity).  If the entity has a single field
 * primary key, the value of that field is returned.  If a composite key is needed, it will be constructed and populated with the correct
 * values.  If a problem occurs, a null will be returned
 * /*from ww w  . j  ava 2  s. c  o  m*/
 * @param object the object to get a primary key value from
 * @return a primary key value
 */
public static Object getEntityPrimaryKeyObject(Object object) {
    final EntityDescriptor descriptor = getEntityDescriptor(object.getClass());
    final Class idClass = descriptor.getIdClass();
    if (idClass != null) {
        try {
            Object pkObject = idClass.newInstance();

            for (FieldDescriptor fieldDescriptor : descriptor.getPrimaryKeys()) {
                Field field = getField(object.getClass(), fieldDescriptor.getName());
                field.setAccessible(true);
                final Object value = field.get(object);
                if (value != null) {
                    final Field fieldToSet = getField(pkObject.getClass(), fieldDescriptor.getName());
                    fieldToSet.setAccessible(true);
                    fieldToSet.set(pkObject, value);
                }
            }

            return pkObject;
        } catch (SecurityException se) {
            LOG.error(se.getMessage(), se);
        } catch (InstantiationException ie) {
            LOG.error(ie.getMessage(), ie);
        } catch (IllegalAccessException iae) {
            LOG.error(iae.getMessage(), iae);
        } catch (NoSuchFieldException nsfe) {
            LOG.error(nsfe.getMessage(), nsfe);
        }
    } else {
        for (FieldDescriptor fieldDescriptor : descriptor.getPrimaryKeys()) {
            try {
                Field field = getField(object.getClass(), fieldDescriptor.getName());
                field.setAccessible(true);
                return field.get(object); // there's only one value, let's kick out
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }

    return null;
}