Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



NullPointerException when using array of string in Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-04-2009
Member
 
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 ());

Reply With Quote
  #2  
Old 25-04-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #3  
Old 25-04-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "NullPointerException when using array of string in Java"
Thread Thread Starter Forum Replies Last Post
String is not occurring in array. rUChIRr Software Development 6 17-06-2011 10:20 PM
How to convert string to char array in java? Baazigar Software Development 6 10-01-2011 06:36 PM
What is java.lang.NullPointerException Logan 2 Software Development 5 27-02-2010 05:30 AM
JavaScript to convert an Array to String KAMANA Software Development 3 09-12-2009 05:30 AM
PHP: array to string? Diwakar_12 Software Development 4 13-04-2009 02:44 PM


All times are GMT +5.5. The time now is 08:24 AM.