Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Android应用程序中的改造实现中访问kotlin类自动生成的getter方法_Java_Android_Kotlin - Fatal编程技术网

Java 在Android应用程序中的改造实现中访问kotlin类自动生成的getter方法

Java 在Android应用程序中的改造实现中访问kotlin类自动生成的getter方法,java,android,kotlin,Java,Android,Kotlin,我正在尝试使用kotlin语言在android应用程序中实现改型库,但我打算使用kotlin的自动生成getter功能获取MovieResponse类的a值 以下是MovierResponse课程: class MovieResponse { @SerializedName("page") private var page : Int? = null @SerializedName("results") private var results : List&l

我正在尝试使用kotlin语言在android应用程序中实现改型库,但我打算使用kotlin的自动生成getter功能获取MovieResponse类的a值

以下是MovierResponse课程:

class MovieResponse {

    @SerializedName("page")
    private var page : Int? = null

    @SerializedName("results")
    private var results : List<Movie>? = null

    @SerializedName("total_results")
    private var totalResults : Int? = null

    @SerializedName("total_pages")
    private var totalPages : Int? = null

    constructor(page: Int?, results: List<Movie>?, totalResults: Int?, totalPages: Int?) {
        this.page = page
        this.results = results
        this.totalResults = totalResults
        this.totalPages = totalPages
    }


}

您的变量在
MovieResponse
类中似乎是私有的,因此您无法从类外访问它。检查。

请发布您的回复,为您提供合适的pojo谢谢,所以我做了
val movies:List=Response.body()!!。结果将变量更改为公共访问级别后!我希望我一切正常?
class MainActivity : AppCompatActivity() {

    private val TAG : String = MainActivity::class.java.simpleName
    val BASE_URL : String = "http://api.themoviedb.org/3/"
    private var retrofit : Retrofit? = null
    private var recyclerView : RecyclerView? = null
    private var API_KEY : String = "166873e095bdb281691220d5ad12610c"

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

        // setup the layout manager
        recycler_view.setHasFixedSize(true)
        recycler_view.layoutManager = LinearLayoutManager(this)

        // get the data
        connectAndGetData()

    }

    /**
     * This method creates an instance of Retrofit
     * and set the base url
     */
    private fun connectAndGetData() {
        if (retrofit == null) {
            retrofit = Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }

        val movieApiService = retrofit!!.create(MovieApiService::class.java)

        val call : Call<MovieResponse> = movieApiService!!.getTopRatedMovies(API_KEY)
        call.enqueue(object : Callback<MovieResponse> {
            override fun onFailure(call: Call<MovieResponse>, t: Throwable) {
            }

            override fun onResponse(call: Call<MovieResponse>, response: Response<MovieResponse>) {
                val movies : List<Movie> = response.body() #<-- stuck here
                recyclerView!!.adapter = MoviesAdapter(movies, R.layout.list_item_movie, applicationContext)
                Log.d(TAG, "Number of movies received: " + movies.size)
            }
        })


    }
}
@SerializedName("results")
        private var results : List<Movie>? = null
val movies : List<Movie> = response.body()
val movies : List<Movie> = response.body().getResults()
{
    "page": 1,
    "total_results": 7444,
    "total_pages": 373,
    "results": [
        {
            "vote_count": 2080,
            "id": 19404,
            "video": false,
            "vote_average": 9,
            "title": "Dilwale Dulhania Le Jayenge",
            "popularity": 16.5,
            "poster_path": "\/uC6TTUhPpQCmgldGyYveKRAu8JN.jpg",
            "original_language": "hi",
            "original_title": "दिलवाले दुल्हनिया ले जायेंगे",
            "genre_ids": [
                35,
                18,
                10749
            ],
            "backdrop_path": "\/mMaxGuQKuH4WUHBwUNhJOetDYE9.jpg",
            "adult": false,
            "overview": "Raj is a rich, carefree, happy-go-lucky second generation NRI. Simran is the daughter of Chaudhary Baldev Singh, who in spite of being an NRI is very strict about adherence to Indian values. Simran has left for India to be married to her childhood fiancé. Raj leaves for India with a mission at his hands, to claim his lady love under the noses of her whole family. Thus begins a saga.",
            "release_date": "1995-10-20"
        },
        {...}
     ]
}