0

I am trying to access a bunch of final static public ints from a class using reflection. This class however doesn't have a constructor - e.g. the android R.id . I am trying to get all int values for these, however I can't seem to access it due to the fact that you can't create the class. I was thinking of possible extending it just to create a constructor, but I am unsure this is wise. Any suggestions? I can't modify R.id or R.array (at least I shouldn't I think).

Thanks in advanced! Jon

2

1 Answer 1

3

That's all you need:

Field field = R.id.class.getField("some_var");
int value = field.getInt(null);
Sign up to request clarification or add additional context in comments.

2 Comments

The point is that you can pass "null" to the get methods to access static members.
Thanks! I have tried that, but I get a null pointer exception, let me get the code and post it... thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.