File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NullPointerException????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException?????" Watch "NullPointerException?????" New topic
Author

NullPointerException?????

ron mccarthy
Greenhorn

Joined: Apr 29, 2004
Posts: 17
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

Joined: Mar 23, 2004
Posts: 82
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

Joined: Apr 26, 2004
Posts: 9
hi,
shouldn't you be doing
ron mccarthy
Greenhorn

Joined: Apr 29, 2004
Posts: 17
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

Joined: Sep 29, 2003
Posts: 299
toField.equals(null)
should be
toField==null
as should all of those comparisons (as a previous poster said)
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
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

Joined: Apr 29, 2004
Posts: 17
Thanks a million.......sorry for before
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException?????