Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.util.Log;
import java.lang.reflect.Field;

public class Main {
    private Field field;

    public static boolean replaceField(String className, String fieldName, Object desObj, Object fieldObj) {
        Field tempField;
        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;
    }

    public void set(Object desObj, Object fieldObj) {
        try {
            field.set(desObj, fieldObj);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}