nullpointerexception initializing map

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    nullpointerexception initializing map

    [code=java]Map<String,Stri ng>[] rowsMap = null;
    ....

    for(int i=0; i<numberOfRows ; i++)
    rowsMap[i]= new HashMap<String, String>();
    [/code]
    throws nullpointerexce ption ?


    thank You
    Last edited by Nepomuk; Nov 15 '08, 02:19 AM. Reason: Please use [CODE] tags!
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    First of all: Please use the [CODE]...[/CODE] tags! You've been a member of bytes.com for long enough to know that.

    About your question: Yes, it does throw a NullPointerExce ption. You're missing a [code=java]rowsMap = new Map<String,Stri ng>[numberOfRows];[/code] before that loop.

    Greetings,
    Nepomuk

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by Nepomuk
      First of all: Please use the [CODE]...[/CODE] tags! You've been a member of bytes.com for long enough to know that.

      About your question: Yes, it does throw a NullPointerExce ption. You're missing a [code=java]rowsMap = new Map<String,Stri ng>[numberOfRows];[/code] before that loop.

      Greetings,
      Nepomuk
      You can't have generics in an array type; make that:

      [code=java]rowsMap = new Map[numberOfRows];[/code]

      kind regards,

      Jos

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        how do i suppress unchecked conversion warning in jsp in java class
        @SuppressWarnin gs ("unchecked" ) works but in jsp eclipse shows a warning

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by oll3i
          how do i suppress unchecked conversion warning in jsp in java class
          @SuppressWarnin gs ("unchecked" ) works but in jsp eclipse shows a warning
          I don't know where to put that @annotation to keep Eclipse's mouth shut in a
          jsp file. Arrays and generics always have been a bit of a problem; read this.

          kind regards,

          Jos

          ps. warnings here are harmless though; don't pay too much attention to them.

          Comment

          • oll3i
            Contributor
            • Mar 2007
            • 679

            #6
            thank You guys a lot i made it (hm we made it) finished everything works :) :) :)
            i can have a break :)
            so till the next project

            Comment

            Working...