Android Field Set setFieldValue(Object obj, String name, Object value)

Here you can find the source of setFieldValue(Object obj, String name, Object value)

Description

set Field Value

Declaration

private static void setFieldValue(Object obj, String name, Object value) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    private static void setFieldValue(Object obj, String name, Object value) {
        Field field;// w  ww  .j av a2  s . c o m
        try {
            field = obj.getClass().getDeclaredField(name);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}

Related

  1. setFieldValue(Object obj, String propertyName, Object value)