• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

string into arraylist

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you try to debug it to see where the NPE is thrown?
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic