From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,T_HK_NAME_FM_MR_MRS autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,27f6b2aa7fe75817,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z19g2000yqk.googlegroups.com!not-for-mail From: "Mr.Spark" Newsgroups: comp.lang.ada Subject: Java.Lang.NullPointerException -- Array Problem -- Couldn't fixed Date: Wed, 24 Feb 2010 17:04:47 -0800 (PST) Organization: http://groups.google.com Message-ID: <735e9720-4b06-46bb-8602-e04590473f57@z19g2000yqk.googlegroups.com> NNTP-Posting-Host: 91.105.117.137 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1267059887 11321 127.0.0.1 (25 Feb 2010 01:04:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 25 Feb 2010 01:04:47 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z19g2000yqk.googlegroups.com; posting-host=91.105.117.137; posting-account=9cnuMgoAAACVm1EM80Y3k6mYMNXtvlB3 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9313 Date: 2010-02-24T17:04:47-08:00 List-Id: 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 ..