comp.lang.ada
 help / color / mirror / Atom feed
* Java.Lang.NullPointerException -- Array Problem -- Couldn't fixed
@ 2010-02-25  1:04 Mr.Spark
  2010-02-25  1:20 ` Jeffrey R. Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mr.Spark @ 2010-02-25  1:04 UTC (permalink / 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 ..



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-02-25 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-25  1:04 Java.Lang.NullPointerException -- Array Problem -- Couldn't fixed Mr.Spark
2010-02-25  1:20 ` Jeffrey R. Carter
2010-02-25  1:20 ` (see below)
2010-02-25 17:52 ` John B. Matthews

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox