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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 36

Thread: Program goes into infinite compilation. University project - Library Program.

  1. #1
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Program goes into infinite compilation. University project - Library Program.

    /**
     * Write a description of class Book here.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Book
    {
        // instance variables - replace the example below with your own
        private int id;
        private String author;
        private String title;
        private boolean isFiction;
     
     
        /**
         * Constructor for objects of class Book
         */
        public Book(String title, String author, int id, boolean isFiction)
        {
            // initialise instance variables
            this.id = 0;
            this.author = author;
            this.title = title;
            this.isFiction = false;
        }
     
        /**
         * Get the name of the book Author.
         * 
         */
        public String getAutor()
        {
            // put your code here
            return this.author;
        }
     
        /**
         * Get the book ID.
         */
        public int getId()
        {
            return this.id;
        }
     
        /**
         * Get the book title.
         * 
         */
        public String getTitle()
        {
            return this.title;
        }
     
        public void setAuthor(String authorName)
        {
            author = authorName;
        }
     
        public void setId(int bookId)
        {
            id = bookId;
        }
     
        public void setTitle(String bookTitle)
        {
            title = bookTitle;
        }    
     
    }

    This is the book Class, every time i click on compile, it goes into an infinite compilation.
    import java.util.ArrayList;
    /**
     * This Class would hold Membership details for the Library.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Member
    {
        // instance variables - These are member object attributes/fields
        private String firstName;
        private String lastName;
        private String phoneNumber;
        private int refNumber;
     
        /**
         * Constructor for objects of class Member
         */
        public Member(String firstName, String lastName, String phoneNumber, int refNumber)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.phoneNumber = phoneNumber;
            this.refNumber = refNumber;
     
        }
     
        /**
         * This is return method for the object firstname.
         * 
         */
        public String getfirstName()
        {
             return this.firstName;
        }
     
        /**
         * Return method for the last name.
         */
        public String getlastName()
        {
            return this.lastName;
        }
     
        /**
         * Return method for the phone number.
         */
        public String getPhoneNumber()
        {
            return this.phoneNumber;
        }
     
        /**
         * Return method for membership reference.
         */
        public int getrefNumber()
        {
            return this.refNumber;
        }
    }


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Program goes into infinite compilation. University project - Library Program.

    It compiles fine in my machine
    Can you please give the details ....like which tool/IDE are using to compile the class ?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Are you sure it is the compile step that is the problem?
    Usually infinite loops happen when the code is executed, AFTER the compilation.

    I don't see a main() method in the posted code. How do you execute the program?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    Are you sure it is the compile step that is the problem?
    Usually infinite loops happen when the code is executed, AFTER the compilation.

    I don't see a main() method in the posted code. How do you execute the program?
    Its all done in the blue J environment..cheers for ur input

    --- Update ---

    Quote Originally Posted by clarky2006 View Post
    Its all done in the blue J environment..cheers for ur input
    its not infinite loop but infinite compilation..it just says compiling and never stops unless i close the window,which makes it impossible to test the programe. cheers

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Sorry, I'm not familiar with blue j.
    Do you know the difference between compiling a program and executing a program?
    Does blue j allow you to compile a java class without trying to execute it?

    Is there a main() method in any of your classes?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Complies good on JGrasp... Try using a different complier or make sure you have the latest version of your complier and java.

  7. #7
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by ashboi View Post
    Complies good on JGrasp... Try using a different complier or make sure you have the latest version of your complier and java.
    Blue J is the java environment our teacher is using to teach us and he wants the project done in blueJ.. cheers

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Do you know the difference between compiling a program and executing a program?
    Does blue j allow you to compile a java class without trying to execute it?

    Is there a main() method in any of your classes?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    import java.util.ArrayList;
     
    /**
     * This is the Library Class which would be used to maintain collections of members
     * and books.
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Library
    {
        // instance variables 
        private ArrayList<Membership> member;
        private ArrayList<Book> books;
     
        /**
         * Constructor for objects of class Library
         */
        public Library()
        {
            // initialised instance variables
            members = new ArrayList<Membership>();
            books = new ArrayList<book>();
        }

    Ye I do know the difference in compilling and running the program..compile is to turn the code into=01010101,binary numbers so computer can read it..there is a compile button on BlueJ. I ve rewritten the library classstill cant compile...it says "cannot find symbol-class Membership".i added the new code..cheers.

    --- Update ---

    So what is the main method and what does it do? i ve not used it before...thanx

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    cannot find symbol-class Membership
    Where is the definition for the Membership class? That message says that the compiler can not find it.

    The main() method is the one called by the java program to start the execution of a class. When you execute this command:
    java TheClassName
    the java program calls the main() method of the TheClassName class.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Please attach a recording so that we can get to the root cause.

  12. #12
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    I don't see a main() method in the posted code. How do you execute the program?
    In BlueJ you have no main() method.
    In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
    The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by minju View Post
    In BlueJ you have no main() method.
    In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
    The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.
    @minju
    Are you saying that the jar files created by bluej are different from other jar files?
    That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    @minju
    Are you saying that the jar files created by bluej are different from other jar files?
    That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
    @Norm
    yes the jar differs from normal ones because it has package.bluej included
    like if you have the classes test1, test2, test3 the jar will have
    META-INF
    test1.class
    test2.class
    test3.class
    README.TXT
    package.bluej

  15. #15
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    @minju
    Are you saying that the jar files created by bluej are different from other jar files?
    That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
    Sorry, my mistake.
    You do need a main() method I remember.
    But maybe clarky2006 is not aware of that because in BlueJ you have the availability to create an object out of a class without a main() method.

  16. #16
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    In BlueJ you have no main() method.
    In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
    The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.
    Thats right there is no main in blue j..

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    there is no main in blue j
    Does that mean you do not use the java command to execute the program? The java command requires a main() method.

    Or does the bluej IDE create a class with a main() method that calls the constructor of the class that you want executed?
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Capture.JPG

    here is a pic of blue j

  19. #19
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    import java.util.ArrayList;
     
    /**
     * A simple model of an auction.
     * The auction maintains a list of lots of arbitrary length.
     *
     * @author David J. Barnes and Michael Kölling.
     * @version 2011.07.31
     */
    public class Auction
    {
        // The list of Lots in this auction.
        private ArrayList<Lot> lots;
        // The number that will be given to the next lot entered
        // into this auction.
        private int nextLotNumber;
     
        /**
         * Create a new auction.
         */
        public Auction()
        {
            lots = new ArrayList<Lot>();
            nextLotNumber = 1;
        }
     
        /**
         * Enter a new lot into the auction.
         * @param description A description of the lot.
         */
        public void enterLot(String description)
        {
            lots.add(new Lot(nextLotNumber, description));
            nextLotNumber++;
        }
     
        /**
         * Show the full list of lots in this auction.
         */
        public void showLots()
        {
            for(Lot lot : lots) {
                System.out.println(lot.toString());
            }
        }
     
        /**
         * Make a bid for a lot.
         * A message is printed indicating whether the bid is
         * successful or not.
         * 
         * @param lotNumber The lot being bid for.
         * @param bidder The person bidding for the lot.
         * @param value  The value of the bid.
         */
        public void makeABid(int lotNumber, Person bidder, long value)
        {
            Lot selectedLot = getLot(lotNumber);
            if(selectedLot != null) {
                Bid bid = new Bid(bidder, value);
                boolean successful = selectedLot.bidFor(bid);
                if(successful) {
                    System.out.println("The bid for lot number " +
                                       lotNumber + " was successful.");
                }
                else {
                    // Report which bid is higher.
                    Bid highestBid = selectedLot.getHighestBid();
                    System.out.println("Lot number: " + lotNumber +
                                       " already has a bid of: " +
                                       highestBid.getValue());
                }
            }
        }
     
        /**
         * Return the lot with the given number. Return null
         * if a lot with this number does not exist.
         * @param lotNumber The number of the lot to return.
         */
        public Lot getLot(int lotNumber)
        {
            if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {
                // The number seems to be reasonable.
                Lot selectedLot = lots.get(lotNumber - 1);
                // Include a confidence check to be sure we have the
                // right lot.
                if(selectedLot.getNumber() != lotNumber) {
                    System.out.println("Internal error: Lot number " +
                                       selectedLot.getNumber() +
                                       " was returned instead of " +
                                       lotNumber);
                    // Don't return an invalid lot.
                    selectedLot = null;
                }
                return selectedLot;
            }
            else {
                System.out.println("Lot number: " + lotNumber +
                                   " does not exist.");
                return null;
            }
        }
    }

    Here is a working Auction class in Blue J with no main method..

    --- Update ---

    I mean in Blue j

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Are you still having problems?
    Is your problem with the bluej program
    or is it with your java program? For example you are getting compiler errors. If you are getting errors you need help with, copy and paste here the full text of the compiler's error messages.

    I can't help you with bluej.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Sorry, my mistake.
    You do need a main() method I remember.
    But maybe clarky2006 is not aware of that because in BlueJ you have the availability to create an object out of a class without a main() method.
    I have been doing introduction to java since september and the tutor has never said any thing about main method. in Blue J you can create an objects on the work bench.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Sounds like the IDE (bluej) is doing some of the work for you and hiding what it is doing. In the real world, you need a main() method.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by clarky2006 View Post
    I have been doing introduction to java since september and the tutor has never said any thing about main method. in Blue J you can create an objects on the work bench.
    Yeah as I mentioned you can create objects out of classes in the environment, but if you export the whole thing you need a main() method.

  24. #24
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    Sounds like the IDE (bluej) is doing some of the work for you and hiding what it is doing. In the real world, you need a main() method.
    Sorry mate, I have been at Uni all day, just got home now..I had a chat with our lecturer today about the Main () method and he said you are right, we need the main method in the real world. He says we would be learning the Main () method and other stuff next semester or year 2..so I was really disappointed because with the money Im paying to be educated, Im not getting my money,s worth. Next semester I would be doing Networking (Cisco), so wont be doing programming..looks like i have to teach my self the rest of it."gutted". But im glad I stumbled on this site, cause I ve learnt more here in 2 days than i ve done at Uni in 7 wks..Cheers guys..

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    My impression of several IDEs is that they are for giving students the flavor of programming without requiring them to know all the dirty details.
    If you want to be a programmer, you need to know the dirty details. Then the question is, When do you teach them? I'll leave that to the academics to figure out the best way to teach a subject.
    If you don't understand my answer, don't ignore it, ask a question.

  26. The Following User Says Thank You to Norm For This Useful Post:

    clarky2006 (November 9th, 2012)

Page 1 of 2 12 LastLast

Similar Threads

  1. [SOLVED] Simple Library Program / Need feedback.
    By ziplague in forum What's Wrong With My Code?
    Replies: 22
    Last Post: May 2nd, 2014, 09:03 PM
  2. Help With My Library Program please.
    By jaydac12 in forum What's Wrong With My Code?
    Replies: 26
    Last Post: September 29th, 2012, 09:31 AM
  3. Having Trouble Using a Project as a Library
    By snowguy13 in forum Java IDEs
    Replies: 0
    Last Post: July 5th, 2012, 08:11 PM
  4. I'm creating a sudoku program that is somehow in an infinite loops.
    By Leiferson in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 18th, 2011, 03:21 AM
  5. Unable to execute the program (no compilation error)
    By Alexie91 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2011, 02:39 PM