Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I solve this problem?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
Based on my code that I have this part

so I needed to declare it as well but it gives me this error and it says it need body please look at my declaration:
protected void name ( Context ctx ) throws SQLException;
and I don't have any thing to put on body part to get ride of this error?!!! how can I solve this issue?
Many thanks,
Elahe
[Error]
WEB-INF/classes/com/srs/bugtrack/S_Bug.java [39:1] Expected the body of the method: name
protected void name ( Context ctx ) throws SQLException;
^
1 error
I put whole code as well to make it more clear for you
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I got idea from this program to write these lines:

protected void name ( Context ctx ) throws SQLException {
Vector vname = Bug.getObjectForTemplate();
ctx.put ( "name", vname );
return;
}
and when you see bellow and find the part that it is exaclty like mine :
protected void addUserList( Context ctx ) throws SQLException {
Vector vBuild = model.getUserInitials();
ctx.put( "listUsers", vBuild );
return;
}
there is no declaration for this and how come it is working and mine is not
Many thanks for your help
Elahe

 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
elahe
It looks like you are defining that method right in the middle of another method. The name method must be outside of the handleRequest method. You don't need a 'template' at all, you might be think of C or C++ for those.
About the only time you need an empty declaration in Java is in an interface or an abstract class.
hope that helps
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave I moved name method before handleRequest but I guess the place is not correct. (I need template I have to show the information with that template)
Could you please take a look that I put it in right place based on what you said?
(BTW after moving it gives me error which says:
WEB-INF/classes/com/srs/bugtrack/S_Bug.java [41:1] 'public Vector getObjectForTemplate() throws java.sql.SQLException' is not a static method
Vector vname = Bug.getObjectForTemplate();
^
WEB-INF/classes/com/srs/bugtrack/S_Bug.java [41:1] Cannot parse initializer
Vector vname = Bug.getObjectForTemplate();
^
2 errors
------------------------------
Thanks,
Elahe
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elahe
You're getting the 'is not a static method' error because when you call that method you are invoking it with the class name - Bug. To use a method like that it has to be a static method. If it is an instance method then you need to create a Bug object and invoke the method on that instance.
hope that helps
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave you are great like always and now I don't have any error but somehow it doesn't pass the object to the template and I guess because this part:
protected void name ( Context ctx ) throws SQLException {
Vector vname = Bug.getObjectForTemplate();
ctx.put ( "name", vname );
return;
}
is out of the handleRequest so what is your advice for this?
Elahe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic