Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

string into arraylist  RSS feed

 
scott beveridge
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a string tokienizer to seperate a string then storing the tokens in an arraylist. I also want to add my own string before each token and I can't just use an array because of later operations.

This code gets a NPE when it runs, and my IDE doesnt like the "stringToObject()"- would someone mind pointing out my mistake.

Thamks guys.

Scott
 
Qi Liang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try to debug it to see where the NPE is thrown?
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this piece of code:



I assume you are also aware that when you don't specify the delimiting characters in the StringTokenizer constructor, it assumes the default delimiters.

If you still run into problems post it again

Vijay
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of interest, what does stringToObject() actually do? (Since Strings are objects... )
 
scott beveridge
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions, I had declared the ArrayList with a value of "null" at the start of the class. Removing this declaration works fine. I can only assume this was a really bad thing to do, but don't really know why.
FYI the (stringToObject()) was in response to the first thing I tried not working, which was as Vijay suggested. I was trying to guess where I made my error.
You can probably tell I'm making this up as I go, and I should warn you to be prepared for more silly beginners questions.

Anyway, it didn't work till I asked for help so I'll credit you guys for fixing it and slink sheepishly back to (blindly) hacking out more mistakes.
Thanks,

Scott
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!