When I try to get a color via getResources().getColor(R.color.yellow)
in a normal Activity I get this exception:
07-12 11:58:38.019: E/AndroidRu
int backgroundColor = Color.YELLOW;
instead of
int backgroundColor = getResources().getColor(R.color.yellow);
Your mDragListener
is a member variable. At the point of initializing the Activity object/instance might not be ready. So calling getResource()
of the Activity will fail.
// inner class or normal class ... change scope if needed
private class DragListener {
int color = 0;
public DragListener(Context context) {
color = context.getResource().getColor(R.color.yellow);
}
}
// activity
private DragListener mDragListener;
public void onCreate(...) {
mDragListener = new DragListener(this);
// more code
}