Noob Droid Question regarding random number

Posted by Pete Herbert Penito on Stack Overflow See other posts from Stack Overflow or by Pete Herbert Penito
Published on 2010-04-16T04:24:59Z Indexed on 2010/04/16 4:33 UTC
Read the original article Hit count: 243

Brand new to droid programming, but would love to learn as much as possible, so I finally got my emulator working correctly, I even got a hello world button to work,

I'm attempting to make this button display a random number, I've googled this and came up with this code:

Random generator = new Random();
int n = generator.nextInt(n);

I fixed the Random function by including some Random java utility.

I'm assuming this code above goes in the .java file of the project, so my button code looks as follows (tested and works):

PopUpText.makeText(v.getContext(), "Hello World", 
PopUpText.LENGTH_LONG).show();

I figured I could replace "Hello World" with n to display the number in the box, however the following error is stopping the compile:

The local variable n may not have been initialized

Any ideas why this is happening? Any advice would be hugely appreciated.

© Stack Overflow or respective owner

Related posts about android

Related posts about random-number-generator