• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException?????

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code that it is being thrown on alledgedly.....
String toField = request.getParameter("to");
String fromField = request.getParameter("from");
String msgField = request.getParameter("msgs");
String empty = "";
int count;

if((toField.equals(null))&&(fromField.equals(null))||(msgField.equals(null))){
System.out.println("Empty");
}
else{
char[] myArray = toField.toCharArray();
System.out.println("fdfd3");
Vector addy = new Vector();
String addressToPut = "";
count = 0;
System.out.println("fdfd4");
for(i = 0; i < myArray.length; i++)
{
System.out.println("tool");
if(myArray[i] == ',')
{
System.out.println("fyyyyyyyyyy");
if(addressToPut.equals(frm))
{
addressToPut = "";
}
if(addressToPut.equals(""))
{
System.out.println("fsdfsdf");
}
else{
addy.add(count, addressToPut);
addressToPut = "";
count++;
System.out.println(count);
}
}
else{
addressToPut += myArray[i];
}
}
addyStr = new String[count];
newAddress = new InternetAddress[count];
for(i = 0; i < count; i++)
{

addyStr[i] = new String();

addyStr[i] = addy.elementAt(i).toString();

newAddress[i] = new InternetAddress(addyStr[i]);

} <----- it actually points to this line
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Well, first - it is easier to read if you use the tags.
Now, regarding your question - sometimes the jvm will not point at the correct line of the exception. this happens sometimes when you change the source, recompile and fail - the jvm will use the old class, but your source has the lines all mixed up.
Did you try it with a debugger?
Also, The line where the exception is thrown is probably not too far away from where the jvm points. Try SOP the references of the arrays you use there.
Nimo.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
shouldn't you be doing
 
ron mccarthy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I am new to the forum and I didnt know about the [CODE] tags, so yeah anyway I didnt try a debugger yet, but I did SOP at the top of the code and it was getting so far and then throwing the exception before it got here *:
[ edited to fix tags -ds ]
[ April 29, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
toField.equals(null)
should be
toField==null
as should all of those comparisons (as a previous poster said)
Brian
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.
Now I get it - sorry for before.
you can not do

this will only work if your string is not null.
If you try to do it on a null string - you get the NullPointerException.
What you should test is if (s==null)
Nimo.
[ April 29, 2004: Message edited by: C. Nimo ]
 
ron mccarthy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a million.......sorry for before
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic