+1  A: 

I'm not sure what are you trying to do with this,

  public SomeClass(){
       new SomeClass(r.nextInt(5));
   }

but I suspect the correct syntax (if you want to call the other constructor) is

  public SomeClass(){
       this(r.nextInt(5));
   }

You should post the code of the outside class to understand your problem.

leonbloy
It's not the subject of his problem. (It's highly possible that it's what he was going to do, even though what he did is also completly correct).
Luno
That doesn't explain the NPE. (Indeed, that would always NPE with `-target 1.3` or less.)
Tom Hawtin - tackline
Yes, I know this this does not explain the NPE, but it's surely a bug nonetheless
leonbloy
Then add it is a comment. (Actually, what I said about 1.3 isn't true. It would be true in a situation involving base classes.)
Tom Hawtin - tackline
+2  A: 

According to the documentation, nextInt only throws an IllegalArgumentException if the parameter is not positive.

My guess is it that you are not calling it with a literal constant 5, but rather with some variable that happens to be zero (or negative).

Heinzi
I rather guess that r itself is null.
leonbloy
+1  A: 

Turns out that I'm an idiot. The exception was being thrown from another call to r.nextInt() on the same line which was taking an uninitialized variable as an argument! Foot is very much in mouth. Will read more carefully in future.

Tom R
No problem, things like that have happened to all of us. :-) Please mark your clarification as "accepted answer" (by clicking on the check mark), so that your question no longer shows up as "unanswered".
Heinzi
+1 for the confession. As Heinzi says, please accept your own response, as a favour to future seekers who might have made the same bloomer.
APC
I can't accept it for another 23 hours it says
Tom R
+1  A: 

I tried reproducing your problem with the sample code. But it works..

import java.util.Random;

public class Test {

public static void main(String[] args) {
    Test test1 = new Test();
    SomeClass obj = test1.new SomeClass();
}

private Random r = new Random();

class SomeClass {
       public SomeClass(){
           new SomeClass(r.nextInt(5));
       }

       public SomeClass(int i){
           System.out.println(i);
       }

}

}

Shekhar
+1  A: 

Too long for a comment, but this code compiles and runs without an NPE. You need to show the code that is a problem. Extract from your current code a short example that demonstrates the issue.

import java.util.Random;

public class SomeOtherClass {
    Random r = new Random();

    class SomeClass {
        public SomeClass() {
            /***/
            new SomeClass(r.nextInt(5));
            /*/
            this(r.nextInt(5)); // Or this.
            /***/
        }

        public SomeClass(int i){
            // ...
        }
    }

    public SomeOtherClass() {
        new SomeClass();
    }

    public static void main(String[] args) {
        new SomeOtherClass();
    }
}
Tom Hawtin - tackline