public class Site { protected class PageNode { protected PageNode down; protected PageNode across; protected PageNode up; protected Page page; } private PageNode currentPage; private PageNode homePage; public Site() { this.homePage=new PageNode(); this.currentPage=this.homePage; PageNode shops=addPage("Shops",this.homePage); addPage("News",this.homePage); PageNode products=addPage("Products",this.homePage); // addPage("Paisley",shops); // addPage("Hamilton",shops); // PageNode kitchen=addPage("Kitchen",products); // addPage("Bedroom",products); // addPage("Kettles",kitchen); // addPage("Cookers",kitchen); // addPage("Toasters",kitchen); } public PageNode addPage(String name,PageNode homePage) { PageNode newNode=new PageNode(); newNode.page=new Page(name); if(this.homePage.down==null) { this.homePage.down=newNode; } else { this.currentPage=this.homePage.down; while(this.currentPage.across!=null) this.currentPage=currentPage.across; this.currentPage.across=newNode; this.currentPage.up=this.homePage; } return currentPage; } public void displayCurrentPage() { PageNode currentPage=this.homePage.down; System.out.println("current page name: "); System.out.println(this.homePage.page.getname()); System.out.println("has links to "); if(currentPage.across==null) System.out.println("list is empty"); else while (currentPage!=null) { System.out.println(currentPage.page.getname()); currentPage=currentPage.across; } } public void selectLink() { // add code for step2 } public void moveUp() { // add code for step3 } public void displaySiteMap() { // add code for step4 } }
and the error is
----jGRASP exec: java SiteTest
1: display current page
2: select link
3: move up
4: display site map
0: quit
select option: 1
current page name:
Exception in thread "main" java.lang.NullPointerException
at Site.displayCurrentPage(Site.java:60)
at SiteTest.main(SiteTest.java:17)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete
Thanks in advance guys