nullpointer exception while try to retrieve the elements from the array object



hi,
i had created the array object by using getter/setter method.while i
try to retrieve the elements from the array object. null pointer
exception raise in line no : 35 and line no: 64 .Any body help me to
over come my problem.here's my coding

//Sample .java for Menu to get List Object to a Array
//getter/setter method is in Menu.java

package example;

import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import java.util.*;
import java.io.*;


public class ParseXml
{

public static void main(String[] args)
{
Menu mainMenu = new Menu();
try{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build( new File("C:/Application/
Specification/ApplicationMenu.xml"));
Element root = ( Element)doc.getRootElement();
List listroot = root.getChildren();
Iterator itr = listroot.iterator();
while( itr.hasNext()){
Element nextChild = ( Element)itr.next();

mainMenu.setDescription( nextChild.getAttribute( "description").getValue());
mainMenu.setMenuID( nextChild.getAttribute( "id").getValue());
getConsolidateMenu( mainMenu, nextChild, 0);
}
}catch( Exception e){
e.printStackTrace();
}
printMenu( mainMenu);
}
public static void getConsolidateMenu( Menu menu, Element current,
int depth){
printSpaces( depth);

System.out.println( current.getAttribute( "description").getValue());
List list = current.getChildren();
Iterator it = list.iterator();
Menu mainMenu = new Menu();
Menu [] subMenu = new Menu[list.size()];
int i = 0;
while( it.hasNext()){
Element child = (Element)it.next();

mainMenu.setDescription( child.getAttribute( "description").getValue());
mainMenu.setMenuID( child.getAttribute( "id").getValue());
subMenu[i] = new Menu();

subMenu[i].setDescription(child.getAttribute( "description").getValue());
subMenu[i].setMenuID( child.getAttribute( "id").getValue());
mainMenu.setSubMenu( subMenu);
getConsolidateMenu( mainMenu, child, depth + 1);
i++;
}
}
public static void printSpaces( int n){
for( int i = 0; i <= n; i++){
System.out.print( " ");
}
}
public static void printMenu( Menu menu){
Menu mainMenu = new Menu();
Menu [] subMenu = mainMenu.getSubMenu();
for( int i = 0; i < subMenu.length; i++){
System.out.println( subMenu[i]);
}
}
}
//Menu Class for ParseXml.java getter/setter method

package example;

public class Menu
{
String menuID;
String description;
Boolean isService;
String serviceID;
Menu [] subMenu;
public void setMenuID( String menuID){
this.menuID = menuID;
}
public String getMenuID(){
return menuID;
}
public void setDescription( String description){
this.description = description;
}
public String getDescription(){
return description;
}
public void setIsService( Boolean isService){
this.isService = isService;
}
public Boolean getIsService(){
return isService;
}
public void setServiceID( String serviceID){
this.serviceID = serviceID;
}
public String getServiceID(){
return serviceID;
}
public void setSubMenu( Menu [] subMenu){
this.subMenu = subMenu;
}
public Menu[] getSubMenu(){
return subMenu;
}
}
Thanks in advance,

cheers,
raja

.



Relevant Pages

  • How to use Log4net TelnetAppender and Trace Listeners
    ... Is there a way to use Log4net and Trace Listeners? ... public static void Initialize(string traceListeners, ... public static void Flush2File(string file, string msg, bool ...
    (microsoft.public.dotnet.framework)
  • Re: must find print packages which can deal with large charts
    ... list available printers, query a named printer, print text and image files ... String inputFileName = null; ... printToFile(outputFileName, outputFileType, ... public static void queryServices{ ...
    (comp.lang.java.gui)
  • Re: alternative to my ClassLoader hack
    ... public static void main(String... ... Just for the record, this runs, but gets an exception. ... String name: /fubar/MyClassLoader.class ... throws ClassNotFoundException, InstantiationException, ...
    (comp.lang.java.programmer)
  • Re: Get regular expression
    ... "ABLATION LESION HEART BY PERIPHERALLY INSERTED CATHETER 37.34", ... private string _text; ... public Entry(string text, string citation): ... public static void AddToList(string line, string citation, ArrayList ...
    (microsoft.public.dotnet.languages.csharp)