DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Feb 2005
    Posts
    24

    Question Issues Initialzing and Accessing Integer Array

    Coding Style: NetBeans IDE 4.0 Beta2 (Java)

    Given an Integer array (global/static) defined within my Class scope, I want to be able to use the integer array from within any function in the class itself.
    However I seem to be having issues accessing the array, what I do is I Initiallize (define the size) the array 1st thing in my main, then later in another function (StartConf) I want to use the array.
    My goal is to increment a value in the array when this function is run (for a specific index).

    Code:
    public class Main {
    
     public static int[] confArray;
    
     public static void main(String[] args) {
       // Each Indexed Integer corresponds to the amount of users in that channel/topic
       int confArray[] = new int[10];
       // I need to INITIALIZE the array = 0 here, currently I can only do it manually confArray[1]=0, etc...
       .. DO SOME STUFF ..
       StartConfs();
     }
    
      public static void StartConfs() {
        confArray[0] = 0;	// THIS FAILS, nullexceptionpointer
        onfArray[0]++;	// THEN OF COURSE THIS FAILS
     }
    So I have 2 major issues:
    1- I need to Initialize my int[] = 0 (so I am sure my counters start at 0)
    2- I need to be able to access it from inside the StartConf function

    Currently if I debug through the code I can see that in my main the int[] is created (still not 100% on the best way to initialize the entire thing = 0)
    However my StartConf function sees it as a NULL int[] (as if it was not created) and generates errors like "nullpointerexception" because the int[] is null (but I initialized it in my main)
    I am trying to use this as a "global variable", am I doing something wrong?
    Any help would be appreciated, Thanks,
    Last edited by Jamie; 04-07-2005 at 04:09 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links