Results 1 to 12 of 12
- 03-11-2009, 02:45 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
Exception in thread "main" java.lang.NullPointerException
i get this message when i m going a library management using packages
System.out.println("Enter the number of books you want to add:");
bookno=Integer.parseInt(s.nextLine());
for(i=0;i<bookno;i++)
b[i].details();
this is my part whre i m getting nullpointer exception
package pack1;
import java.util.*;
public class book
{
public String name,author,publisher;
public int acc;
Scanner s=new Scanner(System.in);
public book()
{
/*this.name=name;
this.author=author;
this.publisher=publisher;
this.acc=acc;*/
}
public void details()
{
System.out.println("Enter the name of the book:");
name=s.nextLine();
System.out.println("Enter the author:");
author=s.nextLine();
System.out.println("Enter the publisher:");
publisher=s.nextLine();
System.out.println("Enter the access number:");
acc=Integer.parseInt(s.nextLine());
}
public void display()
{
System.out.println("The access number of the book is "+acc);
System.out.println("Name of the book "+name);
System.out.println("Author of the book "+author);
System.out.println("Publisher of the book "+publisher);
}
}
this is my thing for getting the details of the book:eek:
-
1) which line throws the exception, and
2) when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 03-11-2009, 02:54 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
thnx a lot i dont kw abt it so its just a beggining rite so i m improve
- 03-11-2009, 02:56 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
b[i].details();
for this line it throws exception
-
One word of unasked for advice: Please avoid unnecessary abbreviations in your posts here. I recommend this for several reasons:
- Programming is an exercise in precision. When you communicate here (or anywhere) about programming issues and questions, you want this communication to be as clear as possible to avoid any chance for ambiguity. I'd say at least half the answers here are requests for clarification. Let's avoid that.
- For many here, English is not their first (or second or third) language. It's hard enough for them to understand what people are posting here much less if it's couched in obscure and non-standard abbreviations.
- Extra letters don't cost anything here, so you might as well use them.
- It makes the poster seem a bit immature and thus for some not worthy of help.
-
as for your error, you likely have not initialized all the objects in the "b" array (terrible name for a variable by the way). When you create an array of objects, it is as if you are creating an empty parking lot. If you want to use some cars in the lot, first you have to fill the lot with cars. Likewise to use objects in the array, first you have to construct some or all of the objects.
- 03-11-2009, 03:02 AM #7
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
ok..thanks a lot i m sory if i hurt u
-
- 03-11-2009, 03:09 AM #9
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
i didnot get what is the do-not-help list
- 03-11-2009, 03:10 AM #10
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
so for my error should i go on with a array which is also object...can i do that
-
you already have an array called b. I see you using it without seeing that you've constructed an array yet and without seeing if you initialized every object in the array. please read up in your text book on using array of objects.
- 03-11-2009, 03:18 AM #12
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
Similar Threads
-
Exception in thread "main" java.lang,NullPointerException
By ljk8950 in forum AWT / SwingReplies: 15Last Post: 10-12-2010, 05:51 PM -
Exception in thread "main" java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 0Last Post: 02-24-2009, 01:19 PM -
Exception in thread "main" java.lang.NullPointerException
By Manfizy in forum New To JavaReplies: 1Last Post: 02-17-2009, 10:54 AM -
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
By hemanthjava in forum AWT / SwingReplies: 3Last Post: 01-29-2008, 01:37 AM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks