File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException?????

 
ron mccarthy
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
C. Nimo
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Himanshu Pathak
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
shouldn't you be doing
 
ron mccarthy
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Brian Pipa
Ranch Hand
Posts: 299
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million.......sorry for before
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic