Kotlin noob help

I’m a total beginner and am sure that this syntax problem can be solved by someone of you in a matter of seconds. What is wrong here?

override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)
    viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
    // TODO: Use the ViewModel

    context?.let { context ->
        ContextCompat.getColor(context, R.color.gaugeRed) }?.let {
            speedView.makeSections(3, it, Section.Style.SQUARE)
        }

        ContextCompat.getColor(context, R.color.gaugeGreen) }?.let {
            speedView.sections[0].color = it
        }

        ContextCompat.getColor(context, R.color.gaugeYellow) }?.let {
            speedView.sections[1].color = it
        }
    }
}

It seems like the context variable isn’t available in the second ContextCompat call anymore. Why is that?

Any help is highly appreciated!

I don’t see anything obvious wrong with it (but then I don’t use android so I’m not familar with the libraries). Can you post the error message you get?

There are a lot (line 40 is the second ContextCompat call):

e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (40, 66): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (40, 68): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (40, 72): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (40, 72): Function declaration must have a name
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 13): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 26): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 27): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 35): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 36): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 43): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 45): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 46): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 47): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 52): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 53): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 64): Expecting member declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 67): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 69): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 73): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (44, 73): Function declaration must have a name
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (47, 9): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (48, 5): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (49, 1): Expecting a top level declaration
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (40, 36): Type mismatch: inferred type is Context? but Context was expected
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (41, 47): Unresolved reference: it
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (45, 17): Unresolved reference: speedView
e: C:\src\private\spillguard\app\src\main\java\com\papamufflon\spillguard\ui\main\MainFragment.kt: (45, 47): Unresolved reference: it

The second and third ContextCompat calls have a right brace } with no matching left brace {.

Oh damn, thank you! That’s it :smiley: