E
E
Eugene2020-04-06 18:53:28
Android
Eugene, 2020-04-06 18:53:28

How can I add a ViewPager to a class?

Good afternoon. I'm starting to learn programming for android. I found a tutorial where you can change screens with a swipe (left-right). When I got to the declaration of ViewPager in MainActivity, I ran into an error (Expecting member declaration).
Here is the code:

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class IntroActivity : AppCompatActivity() {

    private ViewPager screenPager;


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

        //setup ViewPager
        screenPager = findViewById(R.id.screen_viewpager)
    }
}


Here is this line
private ViewPager screenPager;
and doesn't work.
The only thing is that the project was created in Kotlin. Maybe because of this?
Android studio 3.6.1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2020-04-06
@Stavpas

This is a kotlin class. You cannot declare a variable in it in the syntax of java.
You need to write the whole class in one language

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question