Maicol Villarroel
Maicol Villarroel

Reputation: 11

Error when recognizing the assets folder "Expected expression, but a package name was found"

I would like my application to have a typeface, I put my .otf in the assets folder, but at the time of making the code the assets folder does not recognize me I touch the error and I get "Expression expected but a package name found" help. Here I leave my code

val typeface= TypeFace.createFromAssets(*assets*, "circular_std_black.otf")

class FragmentUno : Fragment(){

    override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment

        val typeface = Typeface.createFromAsset(assets, "circular_std_black.otf")
        super.onCreate(savedInstanceState)

        val view: View = inflater.inflate(R.layout.fragment_music, container, false)
        //val btn: Button = view.findViewById(R.id.btnFragment)
        //var btn2: Button = view.findViewById(R.id.btnFragm)

        return view
    }
    companion object {
        fun newInstance() = FragmentUno()
        }
    }

Upvotes: 1

Views: 1193

Answers (1)

alancrux
alancrux

Reputation: 11

You can't just call to assets from a Fragment, first you need to call the activity.

val typeface = Typeface.createFromAsset(activity.assets, "circular_std_black.otf")

Upvotes: 1

Related Questions