Results 1 to 12 of 12
- 11-25-2008, 12:32 AM #1
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
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;
}
- 11-25-2008, 12:34 AM #2
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
Exception in thread "main" java.lang.NullPointerException
at booksmanagement.TakeBooksInformationfromUser(books management.java:40)
- 11-25-2008, 12:35 AM #3
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
????????????????????????/
what is the problem in my code
-
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.
- 11-25-2008, 02:05 AM #5
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
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;
}
}
- 11-25-2008, 02:16 AM #6
hhhmmm...
... and error yuo're getting now would be ....?
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 11-25-2008, 02:19 AM #7
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
the program gives me an infinite loop for the last while
while((inDataBook != null )&&( j<BooksInformation.length))
- 11-25-2008, 02:22 AM #8
Debug...
use println() to see what is happening to the values in program and that way check the logic.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 11-25-2008, 02:25 AM #9
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
thanx i will sea what is the problem now
- 11-25-2008, 02:47 AM #10
Member
- Join Date
- Oct 2008
- Location
- Egypt
- Posts
- 26
- Rep Power
- 0
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-25-2008, 05:12 AM #11
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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. =)
- 11-25-2008, 06:43 AM #12
Similar Threads
-
What did i do wrong
By jpnym15 in forum New To JavaReplies: 8Last Post: 11-17-2008, 10:07 AM -
what's wrong in here!!!
By Annatar in forum New To JavaReplies: 8Last Post: 11-14-2008, 02:55 AM -
So, what am I doing wrong?
By Charles_Smith in forum New To JavaReplies: 0Last Post: 10-29-2008, 02:50 PM -
right or wrong
By jot321 in forum New To JavaReplies: 7Last Post: 09-25-2008, 11:45 AM -
I am Doing Something Wrong But Don't Know What?
By BHCluster in forum New To JavaReplies: 3Last Post: 04-16-2008, 01:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks