set Boolean Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

set Boolean Field

Demo Code


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

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