java - void type not allowed here in servlet -
java - void type not allowed here in servlet -
this java class :
public string year, title,detail; public league(string year,string title,string detail) { this.year=year; this.title=title; this.detail=detail; } public void gettitle() { system.out.println(""+year+""+title+""+detail+""); } this servlet:
protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); //creats set of league leaguelist=new linkedlist(); leaguelist.add(new league("2003","spring","soccer league(spring`03)")); leaguelist.add(new league("2003","summer","summer soccer fest")); leaguelist.add(new league("2003","fall","fall soccer league")); leaguelist.add(new league("2004","spring","summer soccer fest")); leaguelist.add(new league("2004","summer","soccer league(spring`03)")); leaguelist.add(new league("2004","fall","fall soccer league")); } this processrequest() method
out.println("<ul>"); iterator items=leaguelist.iterator(); while(items.hasnext()){ out.println("<li>"+league.gettitle()+"</li>"); } out.println("</ul>"); error is: league.gettitle(); //void type not allowed
the error descriptive. you're returning void or, in other words, gettitle method returns nothing. java can't concatenate result of void (nothing) string.
change method become proper getter:
public string gettitle() { homecoming title; } also, create proper getter methods other fields well:
//year field should int rather string public string getyear() { homecoming year; } public string getdetail() { homecoming detail; } java
Comments
Post a Comment