在我的项目中1小时之前我得到错误说:找不到符号变量EXTRA_MOVIE。
我已经尝试清理项目,重建,重新启动缓存以及所有这些事情。
仍然有错误,是否有人知道发生了什么。 这是我的github:https://github.com/adnxy/MyMovieApp
Bellow是两个有错误的活动:
MoviesAdapter Class:
public class MoviesAdapter extends RecyclerView.Adapter<MainActivity.MovieViewHolder> {
private List<Movie> mMovieList;
private LayoutInflater mInflater;
private Context mContext;
public MoviesAdapter(Context context) {
this.mContext = context;
this.mInflater = LayoutInflater.from(context);
}
@Override
public MainActivity.MovieViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
View view = mInflater.inflate(R.layout.row_movie, parent, false);
final MainActivity.MovieViewHolder viewHolder = new MainActivity.MovieViewHolder(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = viewHolder.getAdapterPosition();
Intent intent = new Intent(mContext, MovieDetailActivity.class);
intent.putExtra(MovieDetailActivity.EXTRA_MOVIE, mMovieList.get(position));
mContext.startActivity(intent);
}
});
return viewHolder;
}
//Ispod koristimo Picasso za slike
@Override
public void onBindViewHolder(MainActivity.MovieViewHolder holder, int position) {
Movie movie = mMovieList.get(position);
Glide.with(mContext)
.load(movie.getPoster())
.into(holder.imageView);
}
@Override
public int getItemCount() {
return (mMovieList == null) ? 0 : mMovieList.size();
}
public void setMovieList(List<Movie> movieList) {
this.mMovieList = new ArrayList<>();
this.mMovieList.addAll(movieList);
notifyDataSetChanged();
//sve u adapter paket
}
下面的MovieDetailActivity:
public class MovieDetailActivity extends AppCompatActivity {
private Movie mMovie;
private Reviews mReviews;
private Genres mGenres;
//private MoviesAdapter.ReviewAdapter rAdapter;
ImageView backdrop;
ImageView poster;
TextView title;
TextView description;
TextView releaseDate;
TextView voteAverage;
ListView genres;
ListView reviews;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
if (getIntent().hasExtra(EXTRA_MOVIE)) {
mMovie = getIntent().getParcelableExtra(EXTRA_MOVIE);
} else {
throw new IllegalArgumentException("Detail activity must receive a movie parcelable");
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle(mMovie.getTitle());
backdrop = (ImageView) findViewById(R.id.backdrop);
title = (TextView) findViewById(R.id.movie_title);
description = (TextView) findViewById(R.id.movie_description);
releaseDate = (TextView) findViewById(R.id.movie_date);
voteAverage = (TextView) findViewById(R.id.movie_rating);
//genres = (ListView) findViewById(R.id.genresArray);
reviews = (ListView) findViewById(R.id.reviewArray);
title.setText(mMovie.getTitle());
description.setText(mMovie.getDescription());
voteAverage.setText(mMovie.getVoteAverage());
releaseDate.setText(mMovie.getReleaseDate());
//nameReview.setList(mGenres.getName());
poster = (ImageView) findViewById(R.id.movie_poster);
String internetUrl = "http://image.tmdb.org/t/p/w500";
Glide.with(this)
.load(mMovie.getPoster())
.override(800, 890)
.into(poster);
Glide.with(this)
.load(mMovie.getBackdrop())
.into(backdrop);
}
摇篮:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.demo.mtin.mtin"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.okhttp:okhttp:2.7.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:support-v4:23.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
}
答案 0 :(得分:0)
编译时错误指出您没有任何名为EXTRA_MOVIE
的成员。根据您发布的代码,(MovieDetailActivity.EXTRA_MOVIE
)是public final static
的{{1}}成员。添加
MovieDetailActivity
到public static final String EXTRA_MOVIE = "EXTRA_MOVIE";