Null point exception
Hi there.
I'm having difficulty with a particular step in my program. I have 2 arrays which I am reading in, putting together and printing on screen. I then give the user an option to save the file (choose a file name etc).
When doing this I keep getting a null pointer exception.
I can display the data in a command prompt, no problem. But I receive a null pointer exception when trying to output to file. Here's my code for outputting to a file -
try{
inputValue2 = input.readLine();
fileOutput2 = inputValue2;
}catch(Exception e){
}
try{
BufferedWriter output2 =new BufferedWriter(new FileWriter(fileOutput2));
for(int i=0;i<2000;i++)
{
if (firstArray[i].charAt(0) == secondArray[i].charAt(0))
output2.write(firstArray[i]+" " + secondArray[i] +"\n");
}
}catch (IOException e){
}
break;
Does anyone have any suggestions as to why I get a null point exception on the line : output2.write ( ..... )
Cheers.
[1688 byte] By [
vinceJa] at [2007-11-27 10:55:14]

Do those arrays actually exist yet?
I guess the NullPointerException actually occurs on this line:if (firstArray[i].charAt(0) == secondArray[i].charAt(0))
when either firstArray[i] or secondArray[i] is null.
> I guess the NullPointerException actually occurs on
> this line:if (firstArray[i].charAt(0) ==
> secondArray[i].charAt(0))
when either
> firstArray[i] or secondArray[i] is null.
EIther that, or his JVM is haunted
Both arrays do exist.
Would it be possible to send the entire program via private message for someone to investigate? Not to keen on posting it all on a public board.
Thanks
> Both arrays do exist.
Prove it :-)
> Would it be possible to send the entire program via
> private message for someone to investigate?
No
> Not to
> keen on posting it all on a public board.
Why not? Everyone else is fine with it
and what, pray tell, makes you imagine that we're dopey enough to post our email addresses here?
> and what, pray tell, makes you imagine that we're
> dopey enough to post our email addresses here?
Reading it, I think he thinks there's a "private message" facility on the forums. Shame there isn't, in some ways. Given the level of troll activity and the ease with which flame wars start, my gladness in the other direction is greater
Add a System.out.println(firstArray) and System.out.println(secondArray) before the loop and show us the results.
jbisha at 2007-7-29 11:55:02 >

> > I guess the NullPointerException actually occurs
> on
> > this line:if (firstArray[i].charAt(0) ==
> > secondArray[i].charAt(0))
when either
> > firstArray[i] or secondArray[i] is
> null.
>
> EIther that, or his JVM is haunted
It happend to me few years ago, I dropped a drip of Eau Bnite onto it, but it became worse. I finally had to burn it.
Tim - http://www.unibroue.com/products/eau.cfm
> Reading it, I think he thinks there's a "private
> message" facility on the forums. Shame there isn't,
> in some ways. Given the level of troll activity and
> the ease with which flame wars start, my gladness in
> the other direction is greater
You wouldn't believe the e-mails some of the people that bare their addresses in their profiles get... I should enable it just for the entertainment value.
@OP:
} catch (IOException e) {
}
Not a smart thing to do. I hope you removed the stack trace printing part for brevity's sake.
@George
> Reading it, I think he thinks there's a "private
> message" facility on the forums.
Yeah, on second read I think I'd really like to unpost my narky comment... alas I must offer my humble appologies.
@OP
I really am Sorry.
@George again.
> Shame there isn't, in some ways.
Agreed.
> Given the level of troll activity and the ease with which flame wars
> start, my gladness in the other direction is greater
Also agreed.
Humans can be such silly creatures... I mean, let's face it, most of us wouldn't compile ;-)
> > Reading it, I think he thinks there's a "private
> > message" facility on the forums. Shame there
> isn't,
> > in some ways. Given the level of troll activity
> and
> > the ease with which flame wars start, my gladness
> in
> > the other direction is greater
>
> You wouldn't believe the e-mails some of the people
> that bare their addresses in their profiles get... I
> should enable it just for the entertainment value.
>
> @OP:
>
> } catch (IOException e) {
> }
>
> Not a smart thing to do. I hope you removed the stack
> trace printing part for brevity's sake.
Just found in our codebase this morning:
public String runReportWithParams(final String path, final String reportName, Map params) throws JRException {
try{
JasperReport jasperReport = getJasperReport(path, reportName);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);
return getReportAsPdf(reportName, jasperPrint);
} catch (JRException e){
e.printStackTrace();
System.exit(1);
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}
return "";
}
Notice how the method declares it throws JRException (which is checked) yet catches it and then kills the app. Nice. I weep for the future
> I weep for the future.
Yup, I'm really not looking forward to rebuilding everything when the McManagement discover the real cost of their little "offshore excursions", but at least it'll pay well.
Calling System.exit() is especially nice in JEE... :) Every dumb problem kills the entire app server.
> > I weep for the future.
>
> Yup, I'm really not looking forward to rebuilding
> everything when the McManagement discover the real
> cost of their little "offshore excursions", but at
> least it'll pay well.
Precisely what happened here, too. Still happening, actually. "Argh! This project's slipping! Bring in busloads more 'contractors'!"
If I didn't know better, I'd say you and I actually worked at the same place
> Precisely what happened here, too. Still happening,
> actually. "Argh! This project's slipping! Bring in
> busloads more 'contractors'!"
That's what I saw, too.
Now it's "we're on the brink of failure - let's even outsource the architects' work, because then we can place the blame on the outsourcers".
Outsorcery, I'll call it.
> > Precisely what happened here, too. Still
> happening,
> > actually. "Argh! This project's slipping! Bring in
> > busloads more 'contractors'!"
>
> That's what I saw, too.
>
> Now it's "we're on the brink of failure - let's even
> outsource the architects' work, because then we can
> place the blame on the outsourcers".
>
> Outsorcery, I'll call it.
I think there's a lot of money to be made simply middling between panicking corporations and high-charging contractors who are good at claiming to be troubleshooters. Hmmmmm