• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on Split()  RSS feed

 
holy god
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, i have a text file which has the following data inside.

Account Id = 123
Name = Matt Damon
Address = 465 Ripley Boulevard, Oscar Mansion, Singapore 7666322
DOB = 10-10-1970
Phone Number = 790-3233
Account Balance = 405600.00

Account Id = 126
Name = Ben Affleck
Address = 200 Hunting Street, Singapore 784563
DOB = 25-10-1968
Phone Number = 432-4579
Account Balance = 530045.00

I have tried to use the split method to split the data into tokens and put them into the various category like account id, name, address etc...but it returns null when i execute the program. Please advise me. Thank You

Below is my code
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "it returns null"...but...

I'd suggest you try using a lot of System.out.println() statements to figure out what your code is doing. If you don't think the split() call is working, put some in after your split() call, and see what is really happening.

Try printing out the length of your temp array. Try writing a quick loop that prints every element in the array. Sure, you'll just delete the code later, but that's ok. When I code, I often end up with HUGE chunks of commented code. As I test and fix, I put in more printlns, then comment them out. I want to keep them for a while, since I know I'll be doing a lot of testing, and don't want to have to re-invent it.

so prove to yourself that the split() call is or is not working. In either case, you can then focus your attention on the correct spot in your code.
 
Rajani Gummadi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is not complete and I'm assuming that you have deliberately removed some. Keeping that aside, where are you seeing null, at what line of hte code. I see tht your for loop is inside your while loop, but in for loop you are using temp[1] being set to all the record attributes, so ideally you are saving the same data....

Try to run this in debug mode and you will find the root cause.
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you know that you can't split Matt and Ben?

I don't think there's anything wrong with your use of the split method, so far as that goes, but you might want to consider what happens when your program reads in a blank line.

As for the rest of the code in your post, there seems to be plenty of weird stuff going on there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!