这是我的配置和异常(exception),我不确定该如何解决?

compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.rithmio.coach"
    minSdkVersion 19
    targetSdkVersion 23
}
09-17 22:52:15.645  15249-15249/com.rithmio.coach E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.rithmio.coach, PID: 15249
    java.lang.NoSuchMethodError: No virtual method getColor(ILandroid/content/res/Resources$Theme;)I in class Landroid/content/res/Resources; or its super classes (declaration of 'android.content.res.Resources' appears in /system/framework/framework.jar)
            at com.rithmio.coach.mobile.fragment.WorkoutsListFragment.onCreateView(WorkoutsListFragment.java:55)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1016)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1197)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1562)
            at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:511)
            at com.rithmio.coach.mobile.MobileMainActivity.onStart(MobileMainActivity.java:269)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
            at android.app.Activity.performStart(Activity.java:6006)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

最佳答案

您需要使用ContextCompat.getColor(),它是Support V4库的一部分(因此它将适用于所有以前的API)。

ContextCompat.getColor(context, R.color.my_color)

您需要通过将以下内容添加到应用程序build.gradle中的dependencies数组中来添加Support V4库:
compile 'com.android.support:support-v4:23.0.1'

如果您关心主题,文档将指定该方法将使用上下文的主题:

08-25 23:16