• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add elements from a file into an Array List

 
Karthik surya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone

I wanted to read a file and then add the contents of the file into an ArrayList.



and then I also had a catch following try. But when I say cr.add() it is not adding . I have also tried to add using:



Can someone give me any idea of doing it.

Thank you.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

When you post code, don't double-click the code button. Make sure your source code is in between a [code] start tag and [/code] end tag. I've fixed your post for you.

About your problem: How do you know "it is not adding"? Does your code compile? Does it run? Do you get any error messages? Does the program do something else than you expected? If so, then what did you expect exactly, and how does the actual output differ from that?
 
Divya Kotamraju
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Even I have the same problem .. IT is giving me a Number format exception. Can someone please help.

Thanks!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you are using token multiple times in line 22. Are you sure that is correct? It's the same string that you are passing to the constructor multiple times. I think you meant to read multiple different tokens from the scanner and pass those for the individual parameters for the constructor.

By the way, why is it that Karthik surya posted the original question, and Divya Kotamraju answers? Are you one person with two accounts? (Oh, now you've edited your answer as if you're someone else???)
 
Divya Kotamraju
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jasper,

No I am not the same person as Karthik. Even I am doing similar kind of assignment. So I have posted as a reply to this particular post.
 
Karthik surya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jasper,

No. and regarding this question it is giving me number format exception. I think token contains the next value of the scanned i/p. So I have used it.

Thanks!!
 
Ed Connery
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik surya wrote:No. and regarding this question it is giving me number format exception. I think token contains the next value of the scanned i/p. So I have used it.
Take a look at Jesper's first post again. He asked you about seven questions, but you only answered one. The others will give you some key clues to solving the problems with your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic