-5

I keep having this error and have no idea why and here is my code below.


public class Movie{

private String title;
private int year;
private int price;
private Genre genre;

public Movie(String title, int year, int price, Genre genre) {
    this.title = title;
    this.year = year;
    this.price = price;
    this.genre = genre;
}

public Movie() {
}

public String getMovieTitle() {
    return title;
}

public int getMovieYear() {
    return year;
}

public int getMoviePrice() {
    return price;
}

public Genre getMovieGenre() {
    return genre;
}

public void setMovieTitle(String title) {
    this.title = title;
}

public void setMovieYear(int year) {
    this.year = year;
}

public void setMoviePrice(int price) {
    this.price = price;
}

public void setMovieGenre(Genre genre) {
    this.genre = genre;
}

public String toString() {
    return  this.year + "\t" + this.title + "\t" + this.genre.toString() + "\t" + "$ " + this.price;
}

}


and then i got this error:

enter image description here

which is a NoSuchMethodException.

I searched about this error, which teached me to add an empty constrcutor and i added it and still got this error. Also, i have all parameters required, why am i still getting this Exception?

can someone help me out pls?

thanks in advance.

Elarbi Mohamed Aymen
  • 1,480
  • 1
  • 11
  • 25
Jamen
  • 99
  • 6
  • 3
    [idownvotedbecau.se/imageofanexception/](http://idownvotedbecau.se/imageofanexception/) - Please include the stack trace (as text) in your question. Marking the line of code that produces the exception may help aswell. – Turing85 Apr 19 '18 at 14:12
  • 1
    You are passing the right parameters, but in a wrong order. – Arnaud Apr 19 '18 at 14:13

3 Answers3

3

By looking in your nosuchmethod exception you are calling the method

Movie("title",1993,g,5)  // here g is the genre you created

And in your constructor the genre comes last. So you need to call it

Movie("title",1993,5,g)  // here g is the genre you created
Veselin Davidov
  • 6,886
  • 1
  • 13
  • 21
0

Your parameters are mixed up. Your constructor expects String, int, int, Genre, but you are passing String, int, Genre, int

sma
  • 8,798
  • 7
  • 46
  • 76
0

You code is with input parameters incorrect.

public Snippet(String string, int i, int j, Genre genre2) {
    // TODO Auto-generated constructor stub
}

You may input an Strig, int, int, Genre.

Julio Amorim
  • 37
  • 2
  • 10