set Int Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

set Int Field

Demo Code


//package com.java2s;
import java.lang.reflect.Field;

public class Main {
    public static void setIntField(Class clazz, String fieldName, int value) {
        Field field;//from   w ww  . j a v  a 2s.c o m
        try {
            field = clazz.getField(fieldName);
            field.setInt(clazz, value);
        } catch (NoSuchFieldException 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();
        }
    }
}

Related Tutorials