Results 1 to 13 of 13
Thread: null pointer exception
- 03-11-2009, 05:23 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
null pointer exception
i am getting null pointer exception at runtime what should be done my program is given below...it is all about library mangement
/*when ever i am trying to search for the book after accessing the number of the book it is giving me null pointer exception and even in display and return also it is giving me null pointer exception*/
Java Code:package pack3; import pack1.*; import pack2.*; import java.util.*; public class user extends pack2.admin { Scanner s=new Scanner(System.in); public int i,choice; admin a=new admin(); //book b[]=new b(); public void staff() { System.out.println("1.Search\n2.Lending\n3.Returning\n4.Display"); System.out.println("Enter the choice:"); choice=Integer.parseInt(s.nextLine()); switch(choice) { case 1: a.search(); break; case 2: System.out.println("Enter the number of books you want to lend:"); int le=Integer.parseInt(s.nextLine());int m=5; for(int i=0;i<le;i++) a.lending(i,m); break; case 3: a.returning(); break; case 4: System.out.println("Enter the access number of the book:"); i=0; while(b[i].acc!=acc1) b[i] = new book(); i=i+1; if(i<bookno) System.out.println("The details of the book is:"); b[i].display(); break; default: System.out.println("wrong choice"); } } public void student() { System.out.println("1.Search\n2.Lending\n3.Returning\n4.Display"); System.out.println("Enter the choice:"); choice=Integer.parseInt(s.nextLine()); switch(choice) { case 1: a.search(); break; case 2: System.out.println("Enter the number of books you want to lend:"); int le=Integer.parseInt(s.nextLine());int m=3; for(int i=0;i<le;i++) a.lending(i,m); break; case 3: System.out.println("Enter the numebr of books you want to return:"); int re=Integer.parseInt(s.nextLine()); for(int i=0;i<re;i++) a.returning(); break; case 4: System.out.println("Enter the access number of the book:"); i=0; while(b[i].acc!=acc1) b[i] = new book(); i=i+1; if(i<bookno) System.out.println("The deatails of the book is:"); b[i].display(); break; default: System.out.println("wrong choice"); } } }
-
Please don't repost the same question twice. I will ask the moderators to delete this thread.
- 03-11-2009, 05:28 PM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
aaaaaaaaaa
- 03-11-2009, 05:30 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
exception is coming in the the search method and the display method and the returning method
- 03-11-2009, 05:31 PM #5
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
i did not get what aaa means
- 03-11-2009, 05:43 PM #6
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 13
What line you're having the npe?
I die a little on the inside...
Every time I get shot.
- 03-11-2009, 05:46 PM #7
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
Java Code:package pack2; import pack1.*; import java.util.*; public class admin { Scanner s=new Scanner(System.in); public book b[]=new book[10]; //b[10]=new book(); public String uname; public int userno=0,bookno,id,i,acc1,ac; public void AddUser() { System.out.println("Enter the name of the user:"); uname=s.nextLine(); System.out.println("Enter the ID number:"); id=Integer.parseInt(s.nextLine()); userno=userno+1; } public void AddBook() { System.out.println("Enter the number of books you want to add:"); bookno=Integer.parseInt(s.nextLine()); for (int i = 0; i < bookno; i++) { b[i] = new book(); // initialize books in array // } //books[3].title = "foo"; b[i].details(); } } public void search() { System.out.println("Give the access number for searching:"); acc1=Integer.parseInt(s.nextLine()); i=0; b[i] = new book(); System.out.println("acc="+acc1); while(b[i].acc!=acc1 && i<10) { i=i+1; b[i] = new book(); System.out.println(i); } if(i<bookno) { System.out.println("The details of the book is:"); b[i].display(); } else System.out.println("The access number not found"); } public void lending(int y,int n) { System.out.println("Enter the id number of user:"); id=Integer.parseInt(s.nextLine()); if(y<=n) { System.out.println("Enter the access number of the book lended:"); ac=Integer.parseInt(s.nextLine()); bookno=bookno-1; } } public void returning() { System.out.println("Enter the access number of the book:"); i=0; while(b[i].acc!=acc1) i=i+1; if(i<bookno) System.out.println("The deatails of the book is:"); b[i].display(); bookno=bookno+1; } public void count() { System.out.println("The number of books :"+bookno); } }
- 03-11-2009, 05:49 PM #8
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 13
No shit Sherlock...
Wait... this code is different than the one in your first post, why didn't you post this the first time? or include it in your first post.
I meant.. what line... the compiler says that.I die a little on the inside...
Every time I get shot.
- 03-11-2009, 05:53 PM #9
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
Actually i am doing this program using the concept of packages...so i am getting the exception in
at pack2.admin.search(admin.java:41)
at pack3.user.student(user.java:58)
at pack4.lib.main(lib.java:55)
-
OK, too many threads on the same subject... I'm bailing out.
- 03-11-2009, 05:58 PM #11
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
ok thats okk i just wanted help from you and i dont think so i got my help..i might have been a starter and this is the way you people help me out
- 03-11-2009, 06:01 PM #12
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 13
Java Code:while(b[i].acc!=acc1 && i<10)
Is that what you want or you made some kind of mistake?
I guess that's the part where the error is occurring- though it would be useful if you could highlight line 41.I die a little on the inside...
Every time I get shot.
- ok thats okk i just wanted help from you and i dont think so i got my help..i might have been a starter and this is the way you people help me out
Similar Threads
-
Null pointer Exception
By peiceonly in forum New To JavaReplies: 8Last Post: 09-05-2010, 07:48 PM -
Null Pointer Exception
By ScKaSx in forum New To JavaReplies: 1Last Post: 01-24-2009, 12:27 PM -
Null Pointer Exception
By Jacinth in forum New To JavaReplies: 4Last Post: 01-22-2009, 02:47 PM -
null pointer exception
By cityguy503@yahoo.com in forum New To JavaReplies: 4Last Post: 08-22-2008, 08:22 PM -
getting a null pointer exception
By Rjava in forum XMLReplies: 4Last Post: 07-16-2008, 06:56 AM
Bookmarks