• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

What on God's low contrast monitor am I doing wrong here? (String.split())

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where I don't understand what goes wrong...



I am consistently getting a NullPointerException immediately following this code when attempting to assign these variables to a map.
I have already been debugging and observed that immediately after the declaration of the arrays, splNm and splDt, they are not containing what they should.

I thought this logic would yield...
(debugging example)
spl[0] == "gradient.top " (yes that whitespace is there... not that it matters)
spl[1] == "60, 60, 60;"

(after variables, splNm and splDT are declared with the .split() method called on the spl[0] and spl[1] elements... respectively assigned...)
splNm == {"gradient", "top"}
splDt == {"60", "60", "60"}

HOWEVER, following the declaration of splNm and splDt, literally at the next possible breakpoint in the code what we see is...

spl[0] == "gradient.top "
spl[1] == "60, 60, 60;" (as expected since we didn't make any changes here...)

splNm == {}
splDt == {""}

>insanity

Here is the rest of the block to give you a better idea of the problem area...



Edit: Also, I'm sorry about the variable names. They're just temporary local variables so I give them wacky names. (spl = split, splNm = split name, splDt = split data)
 
Ranch Hand
Posts: 47
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to say this, but it is better to provide full snippet of code and proper input data - something like this:
http://ideone.com/ZKVDjN
otherwise it is hard to make sure we understand you right.

However the main thing you are missing is that String#split uses not plain strings but regexps, so you should write "\\=" or "\\." for example when you are using special characters.

Also, I'm sorry about the variable names. They're just temporary local variables


Anyway I dare say your method looks long enough and seems to be asking "split me toooo" in several smaller 1-3 lines methods. Then some local variables will become parameters and it would be easier to give them and the inner methods clear names.
 
I'm full of tinier men! And a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic