dave selby
dave selby

Reputation: 145

Just added new fragment but its greyed out in android studio?

Newbe question, android studio, trying to add a new fragment so right click on com....

new>fragment>fragment (blank)

Its created but something is wrong, it has a grey icon and .kt extension

error

Any idea what I am doing wrong ?

Upvotes: 0

Views: 1018

Answers (2)

vishal N
vishal N

Reputation: 162

The difference is the grey icon represents a kotlin file whereas the blue one represents a kotlin class file.android studio makes it a class file if it finds a "class" keyword first after the import statements .Else it will make it as a Kotlin file. Since you didn't include your code here I go with my assumption that you didn't cleared the private ARG_PARAM1 statement thats automatically generated by android studio.Make sure to remove the auto generated code from android studio.

//import statements
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
BlankFragment.Kt(grey-kotlin file)
/**
 * A simple [Fragment] subclass.
 * Use the [BlankFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class BlankFragment : Fragment() {

BlankFragment.kt(blue-class file)

//import statements
class BlankFragment : Fragment() {

Upvotes: 3

Samix
Samix

Reputation: 11

.kt are Kotlin files, when you create a fragment in new>fragment>fragment (blank), chose java as the source language.

Upvotes: 0

Related Questions