From: "Mr.Spark" <malmanea@gmail.com>
Subject: Java.Lang.NullPointerException -- Array Problem -- Couldn't fixed
Date: Wed, 24 Feb 2010 17:04:47 -0800 (PST)
Date: 2010-02-24T17:04:47-08:00 [thread overview]
Message-ID: <735e9720-4b06-46bb-8602-e04590473f57@z19g2000yqk.googlegroups.com> (raw)
Hi Guys, I could not solve this problem, when I tried to throw an
exception the code will not be executed to see
the results.
I think the problem is with the array .
The Code :
import java.util.Random;
public class RunAlgorithm {
static int n = 3; // Number of processes
public static void main(String[] args) {
int random_id;
int Lowest_id;
Random rn = new Random();
SecurityModule[] s = new SecurityModule[n];
// Initializing Security Modules
for (int i = 0; i < n; i++) {
s[i].ID = 0;
s[i].State = false;
}
// Generating Random ID numbers for the Security Modules
for (int i = 0; i < n; i++) {
random_id = rn.nextInt(99) + 1;
s[i].ID = random_id; -- the
problem is in this line
log("Random ID = " + random_id);
}
// To get the lowest ID
Lowest_id = GetLowestID(s);
System.out.println(" The Lowest ID is: " + Lowest_id);
// The initiator with the lowest ID will generate a random number K
> 1
int k = rn.nextInt(9) + 2;
log("Round = " + k);
// Generating a random number i in {1,2,3,...n}
int i = rn.nextInt(3) + 1;
log("i = " + i);
}
public static int GetLowestID(SecurityModule s[]) {
int LowestID = s[0].ID;
for (int i = 1, limit = s.length; i < limit; ++i) {
if (s[i].ID < LowestID)
LowestID = s[i].ID;
}
return LowestID;
}
}
I hope that I can find a solution for this problem.
Thanks guys ..
next reply other threads:[~2010-02-25 1:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-25 1:04 Mr.Spark [this message]
2010-02-25 1:20 ` Java.Lang.NullPointerException -- Array Problem -- Couldn't fixed Jeffrey R. Carter
2010-02-25 1:20 ` (see below)
2010-02-25 17:52 ` John B. Matthews
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox