Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Creating a Library, abstract class created issues. Also need GUI help.

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Location
    Houston, TX
    Posts
    2
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Creating a Library, abstract class created issues. Also need GUI help.

    I am still in my first few months of programming so please bear with me if the problems are stupid-easy to fix.

    When I changed the the Books file to an Abstract class, it created a few compatibility issues. I fixed most, but there are still a couple of errors that I can't wrap my head around.

    Also, when I list the books, it doesn't show in the GUI, and also errors should show in a JOptionPane I guess, not sure. :/

    Help would be greatly appreciated! Hope to have a positive first experience on this website
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Creating a Library, abstract class created issues. Also need GUI help.

    Please post the code you are working on here on the forum.
    there are still a couple of errors
    Please copy the full text of the error messages and paste it here.

    Be sure to wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Location
    Houston, TX
    Posts
    2
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a Library, abstract class created issues. Also need GUI help.

    First error: no suitable method found for add(StringTokenizer)
    	//READ FROM FILE
    	public void LibraryRead()
    	{
    		libraryBooks.clear();
     
    	   	try
    	   	{
    	     	FileReader fr = new FileReader("Library.txt");
    	    	BufferedReader br = new BufferedReader(fr);
     
    	     	String stringRead = br.readLine();
     
    	     	while( stringRead != null )
    	     	{
    	       		StringTokenizer st = new StringTokenizer(stringRead, ", ");
     
    	       	   	String title = st.nextToken();
    	       		String author = st.nextToken();
    	       		String form = st.nextToken();
     
    	       		libraryBooks.add(st); //ERROR LINE
     
    	      		stringRead = br.readLine();
    	     	}
    	     	br.close();
    	   	}
     
    	   	catch(FileNotFoundException fnfe)
    	   	{
     
    	     	System.out.println("ERROR: Unable to find Library.txt");
    	   	}
     
    	   	catch(IOException ioe)
    	   	{
    	     	ioe.printStackTrace();
    	   	}
    	}


    Second error: Book is abstract; cannot be instantiated
    	//WRITE TO FILE
    	public void LibraryWrite (String title, String author, String form)
    	{
    		boolean bookExists = false;
     
    	  	try
    	   	{
    	       	Scanner scan = new Scanner( System.in );
     
    		FileWriter fw = new FileWriter( "Library.txt", true);
    	       	BufferedWriter bw = new BufferedWriter(fw);
     
    	       	ArrayList<Books> LibraryWrite = new ArrayList<Books>();
    	       	LibraryRead();
     
    			for(Books checkBooks : libraryBooks)
    			{
    				if(checkBooks.getTitle().equals(title) &&   checkBooks.getAuthor().equals(author))
    				{
    					bookExists = true;
    				}
    			}
     
    			if(bookExists)
    			{
    				System.out.println("ERROR: Book already exists.");
    			}
     
    			else
    			{
    				Books newBook2 = new Books(title, author, form); //ERROR LINE
    				LibraryWrite.add(newBook2);
     
    				for (Books book : LibraryWrite)
    				{
    					bw.write(book.getTitle() + ", " + book.getAuthor() + ", " + book.getForm() + "\r\n");
    					System.out.println(book);
    				}
    				bw.close();
     
    	        	System.out.println("SUCCESS! File has been written.");
    			}
    		}
     
    	   	catch( IOException ioe )
    	   	{
    	      	ioe.printStackTrace( );
    	   	}
    	}

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Creating a Library, abstract class created issues. Also need GUI help.

    no suitable method found for add(StringTokenizer)
    The compiler could not find an add() method that took a StringTokenizer object as an arg.

    Book is abstract; cannot be instantiated
    You can not create an instance of an abstract class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Abstract class and Interface issues in a code
    By John234 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 09:51 PM
  2. [SOLVED] Abstract method in a non-abstract class
    By bassie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 2nd, 2012, 11:27 AM
  3. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 01:26 PM
  4. Replies: 2
    Last Post: February 28th, 2011, 10:51 AM
  5. creating a controller to allow instances to be created from keyboard
    By ss7 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 2nd, 2009, 01:30 PM

Tags for this Thread