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: Exception in thread "main" java.lang.NullPointerException (HELP!!!)

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Exception in thread "main" java.lang.NullPointerException (HELP!!!)

    Im new in JAVA language... But I need help urgently in this code now.. I got these errors:
    Exception in thread "main" java.lang.NullPointerException
    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1838)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecim al.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at Library.Main.loadMembers(Main.java:994)
    at Library.Main.main(Main.java:40)
    when i compile these codes:

    public static void main(String[] args) throws IOException{
            boolean save = false;
            DisplayMenu();
            String pathPrefix = getPathPrefix();
            Library library = loadLibrary(pathPrefix);
    (Main.java:40)     Member[] members = loadMembers(pathPrefix);
            Book[] books = loadBooks(pathPrefix);
            if(askpassword (library)){
                save = MainMenu(pathPrefix, library, members, books);
            }
            else
                System.out.println("Password invalid. Please try again.");
     
            if(save)
                saveProject(pathPrefix, library, members, books);
            System.exit(0);
        }
     
     public static Member[] loadMembers(String pathPrefix) throws IOException{
            SAXBuilder builder = new SAXBuilder();
            String path = pathPrefix + "libraryMembers.xml";
            File memberXMLFile = new File(path);
            while (! memberXMLFile.exists()){
                path = askForFile(path,"Members XML File");
                memberXMLFile = new File(path);
            }
     
            try{
                Document document = (Document) builder.build(memberXMLFile);
                Element rootNode = document.getRootElement();
                List list = rootNode.getChildren("member");
     
                Member[] members = new Member[list.size()+10];
                //initialize entire member array
                for (int i = 0; i < members.length; i++)
                    members[i] = new Member();
                for (int i = 0; i < list.size(); i++){
                    Element node = (Element) list.get(i);
                     members[i].setisSet();
                     members[i].setfName(node.getChildText("fname"));
                     members[i].setlName(node.getChildText("lname"));
                     members[i].setAdd(node.getChildText("Add"));
                     members[i].setPhone(node.getChildText("Phone"));
                     members[i].seteMail(node.getChildText("eMail"));
                    //members[i].setRestrictedTo(node.getChildText("restrictedTo"));
                     members[i].setmemberStatus(node.getChildText("memberStatus"));
                     members[i].setBirthday(node.getChildText("Birthday"));
    (Main.java:994)  members[i].setfine(Double.parseDouble(node.getChildText("fine")));
                     members[i].setspeFine(Double.parseDouble(node.getChildText("speFines")));
                    //members[i].setCheckBooks(Integer.parseInt(node.getChildText("checkedBooks")));
     
                    //set checkedbooks
                    String checkedBooksString = node.getChildText("Check Books");
                    String[] checkedBooksStringArray = checkedBooksString.split(",");
                    int[] checkedBooks = new int[checkedBooksStringArray.length];
                    for (int checkedBook = 0; checkedBook < checkedBooksStringArray.length; checkedBook++){
                        if (checkedBooksStringArray[checkedBook].equals(""))
                            continue;
                        else
                            checkedBooks[checkedBook] = Integer.parseInt(checkedBooksStringArray[checkedBook]);
                    }
                    members[i].setcheckBooks(checkedBooks);
     
                }
                return members;
            } catch (JDOMException jdomex) {
                System.out.println(jdomex.getMessage());
            }
            return null; 
        }

    Need help!!! Your help will be appreciate
    Last edited by Savage; July 31st, 2014 at 09:50 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Exception in thread "main" java.lang.NullPointerException (HELP!!!)

    What line is the error being thrown from? (Looks like line 40 of your program)

    What are the values of every variable on that line? Use a debugger, or at least some print statements, to answer that question.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NullPointerException (HELP!!!)

    Hi. Im not quite understand your question. Would please explain in more detailed?
    Sorry.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Exception in thread "main" java.lang.NullPointerException (HELP!!!)

    Look at the stack trace to figure out what line of your program is causing the Exception.

    Go to that line. What is that line? What variables are on that line? When that line executes, what are the values of each of those variables?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. "Exception in thread "main" java.lang.NullPointerException" help?
    By redstripes in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 28th, 2014, 08:59 AM
  2. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  3. Replies: 5
    Last Post: December 9th, 2012, 02:25 PM
  4. Exception in thread "main" java.lang.NullPointerException problem.......
    By Adam802 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2012, 02:23 AM
  5. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM

Tags for this Thread