Hi, I picked up this code on daniweb and am trying to get it further.

Here's the class

import java.util.*;
import javax.swing.*;
public class LibraryBook
{
  private String title;
  private String author;
  private int pageCount;

  //contructor for books title, author, page

  public LibraryBook(String bookTitle, String bookAuthor, int bookpageCount)
  {  
     title = bookTitle;
     author = bookAuthor;
     pageCount = bookPageCount;
  }


  //get methods title, author, page
  public String getTitle()
  {
    return title;
  }
  public String getAuthor()
  {
    return author;
  }
  public int getPageCount()
  {
    return pageCount;
  }
  //set methods title, author, page

  public void setTitle(String bookTitle)
  {
    title = bookTitle;
  }
  public void setAuthor(String bookAuthor)
  {
    author = bookAuthor;
  }
  public void setPageCount(int bookPageCount)
  {
    pageCount = bookPageCount;
  }

}

Main Method

import javax.swing.*;
import java.util.*;
public class LibraryBookSort
{
  public static void main(String[] args)
  {
    final int COUNT = 5;
   LibraryBook[] book = new LibraryBook[COUNT];

    String authorName;
    String bookName;
    String pageCount;

    for (int i = 0; i < COUNT; i++)
    {
                  book[i] = new LibraryBook(                  
                  JOptionPane.showInputDialog(null,
                          "Please enter the Book's Name:"),
                      JOptionPane.showInputDialog(null,
                          "Please enter the Author's Name:"),
                      Integer.parseInt(JOptionPane.showInputDialog(null,
                          "Please enter the page count:")));
    }


    // show book
    for (int x = 0; x < COUNT; x++)
      System.out.println("Book " + x + " Author: " + book[x].getAuthor() +
          " Title: " + book[x].getTitle() + " Page Count: " + book[x].getPageCount());
  }

}

I'm getting this error

Exception in thread "main" java.lang.NoSuchMethodError: LibraryBook.<init>(Ljava/lang/String;Ljava/lang/String;I)V


at LibraryBookSort.main(LibraryBookSort.java:27)

on this line

              book[i] = new LibraryBook(

I'm new to this site and to programing so I apologies ahead of time. Can anone help with this Error?

That line is OK, but you have an error on lines 11 and 18 where the capitalisation of the variable name is different.
It's pointless trying to run a program if there are compiler errors.

Edited 2 Years Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.