0

java returns error:model.Movie: method <init>()V not found in xml parser event though I have a constructor in my class it cannot inittialize an object. I have tried rebuilding the project, cannot find anyone with similar problem.

Error:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: hr.algebra.model.Movie: method <init>()V not found
    at hr.algebra.parsers.rss.MovieParser.parse(MovieParser.java:70)
    at hr.algebra.MovieManager.btnUploadFromRssActionPerformed(MovieManager.java:136)
    at hr.algebra.MovieManager.access$000(MovieManager.java:35)
    at hr.algebra.MovieManager$1.actionPerformed(MovieManager.java:87)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

my constructor is:

public Movie(){};

also tried:

public Movie(){
    super();
}

my parser:

public static List<Movie> parse() throws IOException, XMLStreamException, ParseException {
    List<Movie> movies = new ArrayList<>();
    HttpURLConnection con = UrlConnectionFactory.getHttpUrlConnection(RSS_URL);

    try (InputStream is = con.getInputStream()) {
        XMLEventReader reader = ParserFactory.createStaxParser(is);

        Optional<TagType> tagType = Optional.empty();
        Movie movie = null;
        StartElement startElement = null;
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_ELEMENT:
                    startElement = event.asStartElement();
                    String qName = startElement.getName().getLocalPart();
                    tagType = TagType.from(qName);

                    if (tagType.isPresent() && tagType.get() == TagType.ITEM) {
                        movie = new Movie();
                        movies.add(movie);
                    }
                    break;
                case XMLStreamConstants.CHARACTERS:
                    if (tagType.isPresent()) {
                        Characters characters = event.asCharacters();
                        String data = characters.getData().trim();
                        switch (tagType.get()) {
                            case TITLE:
                                if (movie != null && !data.isEmpty()) {
                                    movie.setTitle(data);
                                }
                                break;
                            case PUB_DATE:
                                if (movie != null && !data.isEmpty()) {
                                    LocalDateTime publisheDate = LocalDateTime.parse(data, DateTimeFormatter.RFC_1123_DATE_TIME);
                                    movie.setPublishedDate(publisheDate);
                                }
                                break;
                            case DESCRIPTION:`enter code here`
                                if (movie != null && !data.isEmpty()) {                                        
                                    movie.setDescription(data.substring(data.lastIndexOf("\">") +2 , data.lastIndexOf("<br />")).trim());
                                }
                                break;
                            case ORG_TITLE:
                                if (movie != null && !data.isEmpty()) {
                                    movie.setOriginalTitle(data);
                                }
                                break;
                            case DIRECTOR:
                                if (movie != null && !data.isEmpty()) {
                                    movie.setDirector(getPerson(data));
                                }
                                break;
                            case ACTORS:
                                if (movie != null && !data.isEmpty()) {
                                    List<Person> actors = new ArrayList<>();
                                    String[] peopleInfo = data.split(SEPARATOR);
                                    for (String personInfo : peopleInfo) {
                                        actors.add(getPerson(personInfo));
                                    }
                                    movie.setActors(actors);
                                }
                                break;
                            case DURATION:
                                if (movie != null && !data.isEmpty()) {
                                    movie.setDuration(data);
                                }
                                break;
                            case GENRE:
                                if (movie != null && !data.isEmpty()) {
                                    movie.setGenre(data);
                                }
                                break;
                            case PICTURE_PATH:
                                if (movie != null && !data.isEmpty()) {
                                    handlePicture(movie, data);
                                }
                                break;
                        }
                    }
                    break;
            }
        }
    }

    return movies;
}

Error occurs when creating a new instance in the parser

if (tagType.isPresent() && tagType.get() == TagType.ITEM) {
    movie = new Movie();
    movies.add(movie);
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
kobasa
  • 39
  • 5
  • 1
    You've posted a lot of code, most of it not related to your problem, and also have posted an incomplete error message. Please consider adding text that explains the code and the problem, posting the complete error message, and posting the minimum code necessary to compile and run, or if a compilation error problem, then just enough to cause the compilation error. – Hovercraft Full Of Eels Jul 02 '22 at 16:47
  • Also, your problem has nothing to do with Swing, nothing to do with switch/case and all to do with XML parsing -- focus on that and that alone. – Hovercraft Full Of Eels Jul 02 '22 at 16:49
  • Please look at: [What is a stack trace, and how can I use it to debug my application errors?](https://stackoverflow.com/q/3988788/). For instance what line is, `MovieParser.java:70`, the line indicated by your stack trace? – Hovercraft Full Of Eels Jul 02 '22 at 16:56
  • movie = new Movie(); is the line – kobasa Jul 02 '22 at 16:59
  • Clean and re-build your project – Hovercraft Full Of Eels Jul 02 '22 at 17:11

0 Answers0