Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java time!

Name: Roy 2010-07-13 22:17

Getting a NullPointerException for this snippet, specifically at the "if" statement line. I have initialized and giving values to each of the variables, I cannot for the life of me figure out what is wrong.

    public boolean gradeQuiz(char[] studentAnswers)
    {
        int     l             = 0;
        boolean passedQuiz = false;
        missedQuestions    = new int[ARRAY_SIZE];
       
        for (int i = 0; i < ARRAY_SIZE; i++)
        {
            if (studentAnswers[i] == correctAnswers[i])
            {
                l++;
                missedQuestions[l] = i + 1;
                correct++;
            }

Name: Anonymous 2010-07-13 22:25

Have you considered checking the values of the variables?

Name: Anonymous 2010-07-13 22:29

Use a debugger and inspect the values of studentAnswers and correctAnswers on every iteration of the loop. Even better, if you have an IDE that supports exception breakpoints, add one for NullPointerException on the "if" line.

There are only 2 ways that line can generate an NPE, which are when the array variables are dereferenced. So somehow you're either forgetting to set one of them, or setting it to null midway through execution.

Name: Anonymous 2010-07-13 22:32

>correct
>correctAnswers
Where were these declared?

Name: Anonymous 2010-07-13 22:46

>>3
>>2
>>4
Thanks for the responses. Yes, I did declare correct and correctAnswers.

The class that this code is from is supposed to be used by another program, and this program will have the values for the studentAnswers array. I created a false studentAnswers array to try to work around the NPE, but it had no effect. I am trying to accept studentAnswers from the other class, but I am not completely sure how to do this (this is most likely the reason behind the NPE).

Name: Anonymous 2010-07-13 22:47

Readers, please consider the following:

• Shit coding style
• Vague description of problem
• Incomplete source code
• Java

One can only conclude that this is a trollpost, and so in conclusion, >>1, please get out.

Name: Anonymous 2010-07-13 22:56

>>6
I'm sorry if my coding style isn't quite up to par and I doubt you would want to see all 152 lines of code. Its a vauge description of the problem because I cannot really figure out what's wrong, especially because I thought I was above getting NPEs, but obviously I was wrong. Java is very relevant and useful language.

Name: Anonymous 2010-07-13 23:01

>>6
>[quote]One can only conclude that this is a trollpost[/quote]

ironic

Name: Anonymous 2010-07-14 7:13

>>7
I doubt you would want to see all 152 lines of code
You expect us to detect a mysterious error without the full context?

Name: Anonymous 2010-07-14 9:47

>>9
Why the fuck are you suggesting he actually post the code? Hie yourself to stackoverflow if you want to be so helpful.

Name: Anonymous 2010-07-14 10:17

PERHAPS YOU ARE TRYING TO REFERENCE A NULL POINTER

Name: Anonymous 2010-07-14 11:24




                                    _.---'''''''`--.
                                           '    HAVE        `-.
                                   ____             YOU        \
                                 ,'   ,'.             READ      \
                               ,'    -'  `.             YOUR
                              ,:          |                SICP
                            ,/ `._      _,|                  TODAY?
                           /      `''''' /
                          /              |
                         /              |
                        /              .'
                ,''`._ .'              '
              ,'     `.|              /_
              |       ||             ,' `.
              `                     `     |
                                          |
                                        ,'
                                      -'

Name: Anonymous 2010-07-14 12:03

>>9,10
The paradox of pissiness

Name: Anonymous 2010-07-14 12:08

richard stallman try to strangle me!!!
Hahahahahaha
he now in prison and get fucked by nigger!!!!

Name: Anonymous 2010-07-14 12:15

>>14
Get out.

Name: Anonymous 2010-07-14 13:33

>>14

Richard Stallman touched my junk liberally. he strapped me in to his HURD and he couldnt keep his offensive hands off of me. he was performing many red flag touches. i couldnt believe what the fuck was going on. i told RMS the open source community would not approve of one of the leading free-software figures touching an underage kid for free.

Name: Anonymous 2010-07-14 13:49

>>12
That doesn't look like a dog at all.

Name: Anonymous 2010-07-14 13:55

If you wouldn't enjoy the founder of the FSF touching your junk then you don't deserve to use a computer.

Name: Anonymous 2010-07-14 14:11

NullPointerException

NO EXCEPTIONS

Name: Anonymous 2010-07-15 3:50

>>16
Pubic source software

Name: Anonymous 2011-02-03 7:02

Name: Anonymous 2011-02-04 15:27


Don't change these.
Name: Email:
Entire Thread Thread List