Jim Clermonts
Jim Clermonts

Reputation: 2660

Kotlin convert doesn't work anymore for Android Studio 3.0

Before AS3.0, I could paste Java code and this would be translated into Kotlin automagically with a popup asking me. Now this doesn't work anymore. Also using the shortcut:

"Main menu", "Code", "Convert Java File to Kotlin File"

doesn't work.

Things I've tried: - "File", "Invalidate Cache / Restart" - I have the kotlin plugin installed (in 3.0 this should be by default)

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

    }
}

When I copy-paste

    setContentView(R.layout.activity_main);

It does come up with the convertor popup. And when I paste

ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

Right after this, it actually does work. But when I first paste

    ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

then it doesn't work?

Upvotes: 1

Views: 1173

Answers (1)

Shubhamhackz
Shubhamhackz

Reputation: 7973

Please show which code you're pasting. In order for the converter to run, the code you paste must be a valid Java expression, method or class. I think that can be problem.. or

The problem occurs if you insert Java code without the "import" section - then the converter does not know that the convertible method needs to be overloaded.

Upvotes: 1

Related Questions