因此我正在电影评论应用上进行学校项目。所以这是我的下一个和上一个按钮的代码。下一个按钮可以正常工作而不会崩溃。当我按回它时,它可以工作,但是一旦它到达了第一部电影,我又回按了该应用程序便崩溃了。
void OnCollisionEnter2D(Collision2D col){
FixedJoint2D myjoint = gameObject.AddComponent<FixedJoint2D>();
myjoint.connectedBody = col.rigidbody;
}
我的按钮代码。
private Movie movies[]= new Movie[5];
public MovieCollection(){
prepareMovies();
}
public Movie searchById(String id){
Movie movie = null;
for(int index=0; index < movies.length; index++){
movie = movies[index];
if(movie.getId().equals(id)){
return movie;
}
}
return movie;
}
public Movie getNextMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++) {
String tempMovieId = movies[index].getId();
if (tempMovieId.equals(currentMovieId) && (index < movies.length - 1)) {
movie = movies[index + 1];
break;
}
}
return movie;
}
public Movie getPrevMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++){
String tempMovieId = movies[index].getId();
if(tempMovieId.equals(currentMovieId) && (index > 0)){
movie = movies[index - 1];
break;
}
}
return movie;
}
错误报告谁可以告诉我我的代码出了什么问题。谢谢
public void goNext(View view){
Movie nextMovie = movieCollection.getNextMovie(movieId);
if(nextMovie != null){
movieId = nextMovie.getId();
title = nextMovie.getTitle();
plot = nextMovie.getPlot();
movieArt = nextMovie.getMovieArt();
rating = nextMovie.getRating();
review1 = nextMovie.getReview1();
review2 = nextMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}
public void goPrevious(View view){
Movie prevMovie = movieCollection.getPrevMovie(movieId);
if (prevMovie != null){
movieId = prevMovie.getId();
title = prevMovie.getTitle();
plot = prevMovie.getPlot();
movieArt = prevMovie.getMovieArt();
rating = prevMovie.getRating();
review1 = prevMovie.getReview1();
review2 = prevMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}