Results 1 to 3 of 3

Thread: NullPointerException when using array of string in Java

  1. #1
    Join Date
    Feb 2008
    Posts
    624

    NullPointerException when using array of string in Java

    I use an API to segment the text into sentences. In the future I want to retrieve each sentence in a case of an array of string.

    Code:
    String [] tab = null; 
      for (int i=0; i<annotations.size() i++) { 
    				  Annotation annotation = annotations. Get (i); 
      if (annotation!= null && (annotation.getType().equals ("Sentence"))) { 
      DocumentContent content = currDoc.GetContent(); 
          Node = startNode annotation.GetStartNode(); 
             Node = endNode annotation.GetEndNode(); 
             long start = startNode.getOffset(); 
             long end = endNode.getOffset(); 
      tab [i] = content. getContent (start, end). toString (); 
      }
    This Code generates an exception: Exception in thread "main" java.lang.NullPointerException.

    Note that this same code works fine by putting

    Code:
    System. Out. Println (i + ":" + content. GetContent (start, end). ToString ());

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: NullPointerException when using array of string in Java

    Quote Originally Posted by Sean J View Post
    This Code generates an exception: Exception in thread "main" java.lang.NullPointerException.
    You manipulating a null at line mentioned in your exception.

  3. #3
    Join Date
    May 2008
    Posts
    945

    Re: NullPointerException when using array of string in Java

    The problem comes from
    Code:
    String [] tab = null;
    or rather that you had not initialized tab.

    Code:
    String [] tab = new String [annotations.size ()]
    should solve the problem.

Similar Threads

  1. String is not occurring in array.
    By rUChIRr in forum Software Development
    Replies: 6
    Last Post: 17-06-2011, 10:20 PM
  2. How to convert string to char array in java?
    By Baazigar in forum Software Development
    Replies: 6
    Last Post: 10-01-2011, 06:36 PM
  3. What is java.lang.NullPointerException
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 05:30 AM
  4. JavaScript to convert an Array to String
    By KAMANA in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 05:30 AM
  5. PHP: array to string?
    By Diwakar_12 in forum Software Development
    Replies: 4
    Last Post: 13-04-2009, 02:44 PM

Tags for this Thread

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
  •  
Page generated in 1,718,110,314.75614 seconds with 17 queries