Results 1 to 12 of 12
  1. #1
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default what si the wrong with tihs cose?????

    public static String[] TakeBooksInformationfromUser() throws IOException{
    int j=0;
    for(int i=0;i<BooksInformation.length;i++)
    if(BooksInformation[i].equals(" "))
    {j=i;
    break;}
    else
    continue;

    BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
    inDataBook =" ";

    while(inDataBook != null && j<BooksInformation.length){
    System.out.print("Enter the book information withe a (,) between it ");
    inDataBook=in.readLine();
    BooksInformation[j]=inDataBook;
    j++;
    }

    return BooksInformation;
    }

  2. #2
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    Exception in thread "main" java.lang.NullPointerException
    at booksmanagement.TakeBooksInformationfromUser(books management.java:40)

  3. #3
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    ????????????????????????/
    what is the problem in my code

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're trying to use an object before initializing it. You must fill the array with viable objects before you can try to call any methods on them.

  5. #5
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    i did it but what is the problem now???

    import java.io.*;
    public class booksmanagement {

    private static String [] BooksInformation = new String[100];
    public booksmanagement(){
    for(int x=0; x<BooksInformation.length;x++)
    BooksInformation[x]=null;
    }
    private static String inDataBook;

    //method to load from the file into the array

    public static String[] LoadBooksInFormation() throws IOException{

    BufferedReader in=new BufferedReader(new FileReader("C:\\Users\\VooDoo\\Desktop\\LibrarySys tem\\books.txt"));

    String read;
    int m=0;
    while((read = in.readLine()) != null && m<BooksInformation.length){

    for(int i=0 ;i<BooksInformation.length;i++){
    BooksInformation[i]=read;
    }
    m++;
    }
    in.close();
    return BooksInformation;
    }


    // method to take data from the user and write it in the array and the file
    public static String[] TakeBooksInformationfromUser() throws IOException{
    int j=0;
    for(int i=0;i<BooksInformation.length;i++){
    if(BooksInformation[i].equals(null))
    {j=i;
    break;}
    else
    continue;
    }
    BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
    inDataBook="";

    while((inDataBook != null )&&( j<BooksInformation.length)){
    System.out.println("Enter the book information withe a (,) between it ");
    inDataBook=in.readLine();
    BooksInformation[j]=inDataBook;

    BufferedWriter out= new BufferedWriter(new FileWriter("C:\\Users\\VooDoo\\Desktop\\LibrarySys tem\\books.txt",true));
    out.write(inDataBook+"\n");
    out.close();

    j++;
    }

    return BooksInformation;
    }

    }

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default hhhmmm...

    ... and error yuo're getting now would be ....?
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    the program gives me an infinite loop for the last while

    while((inDataBook != null )&&( j<BooksInformation.length))

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Debug...

    use println() to see what is happening to the values in program and that way check the logic.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    thanx i will sea what is the problem now

  10. #10
    sheckoo is offline Member
    Join Date
    Oct 2008
    Location
    Egypt
    Posts
    26
    Rep Power
    0

    Default

    the problem is still exist and i dont know what to do please would u please to trace it and tell me why it dont get out from the loop

  11. #11
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    either inDataBooks is never set to null, or j is never incremented. find out which one it is, then find out why either statement isn't fulfilled, meaning pay attention to the one line of code where the variable is modified and research the methods and objects used to update your variable. =)

  12. #12
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default what did you see?

    What did the println()'s show when you used them in your program to trace the flow of the data?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. What did i do wrong
    By jpnym15 in forum New To Java
    Replies: 8
    Last Post: 11-17-2008, 11:07 AM
  2. what's wrong in here!!!
    By Annatar in forum New To Java
    Replies: 8
    Last Post: 11-14-2008, 03:55 AM
  3. So, what am I doing wrong?
    By Charles_Smith in forum New To Java
    Replies: 0
    Last Post: 10-29-2008, 03:50 PM
  4. right or wrong
    By jot321 in forum New To Java
    Replies: 7
    Last Post: 09-25-2008, 12:45 PM
  5. I am Doing Something Wrong But Don't Know What?
    By BHCluster in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 02:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •