Reflection for a Field going wrong

Posted by TiGer on Stack Overflow See other posts from Stack Overflow or by TiGer
Published on 2010-06-01T09:32:18Z Indexed on 2010/06/01 9:43 UTC
Read the original article Hit count: 208

Filed under:
|
|
|

Hi, I have been trying to use reflection for a specifiec Field in the android.os.build class, the MANUFACTURER field... I have tried by using this code :

try
    {
        Class myBuildClass = android.os.Build.class;
        Field m1 = Build.class.getDeclaredField("MANUFACTURER");
        validField = true;

        manufacturer = Build.MANUFACTURER;
    }
    catch(Exception ex)
    {
        manufacturer = Build.PRODUCT;
        System.err.println("getDeviceSpecifics, got an exception during getting Field : " + ex.toString());
    }

I am gettign the following errors :

06-01 11:26:37.639: WARN/dalvikvm(7342): VFY: unable to resolve static field 2 (MANUFACTURER) in Landroid/os/Build;
06-01 11:26:37.639: WARN/dalvikvm(7342): VFY:  rejecting opcode 0x62 at 0x0048

06-01 11:26:37.639: WARN/dalvikvm(7342): VFY:  rejected Lmobilaria/android/managementModule/Management;.getDeviceSpecifics ()V
06-01 11:26:37.639: WARN/dalvikvm(7342): Verifier rejected class Lmobilaria/android/managementModule/Management;

And when debugging I noticed that InvocationtargetException is continuesly thrown, so I am guessing I haven't been implementing the whole Reflection principle correctly... Any idea where things are going wrong or otherwise on how to implement Refelction for a single Field correctly ?

© Stack Overflow or respective owner

Related posts about java

Related posts about android