Results 1 to 6 of 6

Thread: [RESOLVED] an array index reference..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    82

    Resolved [RESOLVED] an array index reference..

    hi all,
    i'm jst struggling with a fundermental problem with the addressing method of a 2-D array. it's very simple problem but i've jst been unable to find the solution ..
    the problem is...

    im having a 2-D array of integer..
    int[][] myArray = new int[5][10];
    and i need to refer one whole row at once... say to refer the 2nd whole row...
    how could i do it?
    it's giving an error when i use " myArray[1] " to refer the 2nd row.
    could you pls help me to solve this problem...
    thanking in advance.
    bye

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: an array index reference..

    What's the error?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    82

    Re: an array index reference..

    Exception in thread "main" java.lang.NullPointerException
    at com.xpl.Client.loadUserStories(Client.java:152)
    at com.xpl.Client.main(Client.java:43)

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: an array index reference..

    I don't know what's throwing that exception, you should show us some code if you need more help

    The null pointer exception is thrown when an application uses a null value where an object is expected.

    Here is also a code sample on using a 2D array
    Code:
        public static void main(String[] args) throws ClassNotFoundException {
            int[][] myArray = new int[5][10];
            print(myArray[1]);
        }
        
        public static void print(int[] array)
        {
            for(int i:array){
                System.out.println(i);
            }
        }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    82

    Re: an array index reference..

    ComputerJy,
    thanks for ur help. i jst got the error, an object was accessed before initializing.. now it woking porperly..ya i got ur point.. have to give some more details when asking something..
    thanks for advices;

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: an array index reference..

    you're welcome
    If you are done here, please don't forget to mark the thread resolved from the "Thread Tools" menu
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width