Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. jagged array error message

jagged array error message

Scheduled Pinned Locked Moved C#
questiondata-structureshelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpvkrishnadhar
    wrote on last edited by
    #1

    hi learned jagged array today and was working with them! came across two error messages int [][]j1=new int[][]; now i get two error messages displayed 1) when i keep my cursor/pointer on the new int part then i get to see the following error message "Wrong number of indices inside[];excepted1" 2) when i keep my cursor/pointer on the indices then the following error message is displayed "Array creation must have array size or array "initializer". 2nd error message is pretty straight forward as it explains about the need to declare an array(row) size or initialize the(row)array in case of JAGGED ARRAYS my question here is what is the meaning of the first error message;

    S L OriginalGriffO 3 Replies Last reply
    0
    • M mpvkrishnadhar

      hi learned jagged array today and was working with them! came across two error messages int [][]j1=new int[][]; now i get two error messages displayed 1) when i keep my cursor/pointer on the new int part then i get to see the following error message "Wrong number of indices inside[];excepted1" 2) when i keep my cursor/pointer on the indices then the following error message is displayed "Array creation must have array size or array "initializer". 2nd error message is pretty straight forward as it explains about the need to declare an array(row) size or initialize the(row)array in case of JAGGED ARRAYS my question here is what is the meaning of the first error message;

      S Offline
      S Offline
      Satish Pai
      wrote on last edited by
      #2

      Hi, You have the answer. It is what you have said. We need to specify the array size. Regards, Satish Pai

      M 1 Reply Last reply
      0
      • S Satish Pai

        Hi, You have the answer. It is what you have said. We need to specify the array size. Regards, Satish Pai

        M Offline
        M Offline
        mpvkrishnadhar
        wrote on last edited by
        #3

        oops! that was a typo mistake! i was asking about the first error message!

        1 Reply Last reply
        0
        • M mpvkrishnadhar

          hi learned jagged array today and was working with them! came across two error messages int [][]j1=new int[][]; now i get two error messages displayed 1) when i keep my cursor/pointer on the new int part then i get to see the following error message "Wrong number of indices inside[];excepted1" 2) when i keep my cursor/pointer on the indices then the following error message is displayed "Array creation must have array size or array "initializer". 2nd error message is pretty straight forward as it explains about the need to declare an array(row) size or initialize the(row)array in case of JAGGED ARRAYS my question here is what is the meaning of the first error message;

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          int [][]j1=new int[][];

          You are asking the system to create an array, but you have not told it how big the array should be.

          Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

          1 Reply Last reply
          0
          • M mpvkrishnadhar

            hi learned jagged array today and was working with them! came across two error messages int [][]j1=new int[][]; now i get two error messages displayed 1) when i keep my cursor/pointer on the new int part then i get to see the following error message "Wrong number of indices inside[];excepted1" 2) when i keep my cursor/pointer on the indices then the following error message is displayed "Array creation must have array size or array "initializer". 2nd error message is pretty straight forward as it explains about the need to declare an array(row) size or initialize the(row)array in case of JAGGED ARRAYS my question here is what is the meaning of the first error message;

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            The problem is that you are defining j1 as "an array of [arrays of ints]". So when you try to create a new instance of it, you have to tell it how many "arrays of ints" this instance will be. If you defined

            int[] arr = new int[];

            then it is clearly wrong: it acan't allocate space for an unknown number of objectes, you have to say

            int[] arr = new int[7];

            So enter a size for the array:

            int[][] j1 = new int[100][];

            And all will be well.

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            M 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              The problem is that you are defining j1 as "an array of [arrays of ints]". So when you try to create a new instance of it, you have to tell it how many "arrays of ints" this instance will be. If you defined

              int[] arr = new int[];

              then it is clearly wrong: it acan't allocate space for an unknown number of objectes, you have to say

              int[] arr = new int[7];

              So enter a size for the array:

              int[][] j1 = new int[100][];

              And all will be well.

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              M Offline
              M Offline
              mpvkrishnadhar
              wrote on last edited by
              #6

              oooh! now i get it!

              OriginalGriffO 1 Reply Last reply
              0
              • M mpvkrishnadhar

                oooh! now i get it!

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                I love those "lightbulb" moments! :laugh:

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups