• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to replicate my own database using an arrayList  RSS feed

 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am attempting to create a mini database (a directory so to say) using an ArrayList data structure. I'm getting an error though in my addPerson() method and I can't pinpoint the reason why I'm getting an error. Please look at the source code:



What am I doing wrong? My add method get's an error after the prompt for the first name.
 
Paul Clapham
Sheriff
Posts: 22813
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An error?

Could you be more specific? After all the natural thing for a programmer to do, when faced with an error, is to read the error message. You haven't allowed us to do that.
 
Tobias Bachert
Ranch Hand
Posts: 86
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the error-message in such cases.

 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry ladies and gents I'm getting the following error:

Welcome to the people directory please make a choice from the list below:
-------------------------------------------------------------------------
1. Add a person to the directory.
2. Remove a Person from the directory.
3. View the User Directory.
4. Exit the directory.
1
Enter the first name of the Person you would like to add:
Timothy
Exception in thread "main" java.lang.NullPointerException
at Lab2.addPerson(Lab2.java:52)
at Lab2.main(Lab2.java:25)
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the error nevermind. Thanks!
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My next question now is in regards to displaying items within the arrayList itself. It does not seem to print all the entered data. It only prints the very last entry in the arrayList. Why is that? Since this ADT is already written, I don't think I need to assign anything to next or last. Thanks! Please let me know!
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post your latest code?
 
Paul Clapham
Sheriff
Posts: 22813
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naziru Gelajo wrote:My next question now is in regards to displaying items within the arrayList itself. It does not seem to print all the entered data. It only prints the very last entry in the arrayList.


If I take that literally, the answer is "That's because you only have one entry in the arrayList." Your loop prints all of them -- so if it's only printing one entry, it must follow that "all of them" is one entry and therefore the list only contains one entry.

However I'm going to interpret the question as "The code prints the last data entered repeatedly." Even though you didn't mention "repeatedly". That would mean that you only have one Person object and all of the entries in the arrayList refer to that single object. It would also mean that when you accept data from the user, you change the data in that single Person object instead of creating a new one.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!