我正在开发一个电影管理器应用程序,显示即将上映和现在正在播放的电影列表。
这里的错误说Movie.graphics.Movie中的Movie()不公开,不能从外部包中访问。
请帮忙。
package com.example.android.moviemanager.activity.fragments;
import android.graphics.Movie;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.android.moviemanager.R;
import com.example.android.moviemanager.activity.adapters.MovieRecyclerViewAdapter;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* A simple {@link Fragment} subclass.
*/
public class now_playing extends Fragment {
@BindView(R.id.rvMovie)
RecyclerView rvMovie;
List<Movie> movies;
public now_playing() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_now_playing, container, false);
ButterKnife.bind(this, view);
initializeData();
LinearLayoutManager llm=new LinearLayoutManager(this.getContext());
rvMovie.setHasFixedSize(true);
rvMovie.setLayoutManager(llm);
MovieRecyclerViewAdapter adapter= new MovieRecyclerViewAdapter(getContext(), movies);
rvMovie.setAdapter(adapter);
return view;
}
private void initializeData() {
movies = new ArrayList<Movie>();
movies.add(new Movie("277834", "Moana", "In Ancient Polynesia, when a terrible curse incurred by Maui reaches an impetuous Chieftain's daughter's island, she answers the Ocean's call to seek out the demigod to set things right.", 6.5f, 854, "/z4x0Bp48ar3Mda8KiPD1vwSY3D8.jpg", "/1qGzqGUd1pa05aqYXGSbLkiBlLB.jpg"));
movies.add(new Movie("121856", "Passengers", "A spacecraft traveling to a distant colony planet and transporting thousands of people has a malfunction in its sleep chambers. As a result, two passengers are awakened 90 years early.", 6.2f, 745, "/5gJkVIVU7FDp7AfRAbPSvvdbre2.jpg", "/5EW4TR3fWEqpKsWysNcBMtz9Sgp.jpg"));
movies.add(new Movie("330459", "Assassin's Creed", "Lynch discovers he is a descendant of the secret Assassins society through unlocked genetic memories that allow him to relive the adventures of his ancestor, Aguilar, in 15th Century Spain. After gaining incredible knowledge and skills he’s poised to take on the oppressive Knights Templar in the present day.", 5.3f, 691, "/tIKFBxBZhSXpIITiiB5Ws8VGXjt.jpg", "/5EW4TR3fWEqpKsWysNcBMtz9Sgp.jpg"));
movies.add(new Movie("283366", "Rogue One: A Star Wars Story", "A rogue band of resistance fighters unite for a mission to steal the Death Star plans and bring a new hope to the galaxy.", 7.2f, 1802, "/qjiskwlV1qQzRCjpV0cL9pEMF9a.jpg", "/tZjVVIYXACV4IIIhXeIM59ytqwS.jpg"));
movies.add(new Movie("313369", "La La Land", "Mia, an aspiring actress, serves lattes to movie stars in between auditions and Sebastian, a jazz musician, scrapes by playing cocktail party gigs in dingy bars, but as success mounts they are faced with decisions that begin to fray the fragile fabric of their love affair, and the dreams they worked so hard to maintain in each other threaten to rip them apart.", 8, 396, "/la-la-land-ryan-gosling-emma-stone-600x413.jpg", "/nadTlnTE6DdgmYsN4iWc2a2wiaI.jpg"));
}
}
答案 0 :(得分:1)
您有两个同名Movie
的类,原因是编译器不了解您要引用哪个Movie
类。
请使用完整的android.graphics.Movie
或Your-Package-here.Movie
来访问电影类。
但是,如果重命名Model类Movie
,则会解决此问题。