Help with compile errors
I have the following piece of code but when i compile i get errors can anybody see why i am getting these error?
TableTag.java:16:'try' without'catch' or'finally'
try{
^
TableTag.java:52: illegal start of type
}catch (IOException ex){
^
TableTag.java:56: <identifier> expected
return SKIP_BODY;
^
TableTag.java:60:'class' or'interface' expected
}// TagList
^
TableTag.java:61:'class' or'interface' expected
^
5 errors
Why is the catch not getting reached? have i added an extra { or something?
import java.io.*;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
// do i need to import mysite?
publicclass TableTagextends BodyTagSupport{
publicint doAfterBody(){
BodyContent body = getBodyContent();
String text = body.getString().trim();// get bodycontent trip whitespace
List list = body;
if (list ==null)return SKIP_BODY;;
try{
JspWriter out = body.getEnclosingWriter();
out.println("<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
"<TR BGCOLOR=\"#AADDFF\">\n" +
" <TH>Artist\n" +
" <TH>Title\n" +
" <TH>Image"
);
Iterator it = list.getpricePassed().iterator();
while( it.hasNext() ){
MySite.videoBean vids = (MySite.videoBean) it.next();
out.println("<TR BGCOLOR=\"#FFAD00\">\n" +
"<TD><Center><B>" + vids.getArtist() +"</TD>" +
"<TD><Center><B>" + vids.getTitle() +"</TD>" +
"<TD>" +"<IMG width=75 height=75 SRC=\"http://localhost:8080/examples/images/video/" + vids.getImage() +"\"> " +"</TD></TR>\n" );
}// end while
}
out.println("</TABLE>");
}catch (IOException ex){
thrownew JspTagException(ex.getMessage());
}// try
return SKIP_BODY;
}// doAfterBody()
}// TagList
}// end while
} // unnecessary close bracket
out.println("</TABLE>");
} catch (IOException ex) {
proper indentation help you a lot ....
you need to step back and do some more fundamental excercises. yeh, we can tell you how to fix this problem, but you won't - despite what you might think now - understand why it's a fix. I've seen you post a fair few questions here recently, most of which would not be asked if you just studied the basics a bit more. you need to learn how to read compiler output, and stack traces. nothing, nothing will accelerate your learning and your productivity more than that. the compiler output is incredibly useful as soon as you realise it isn't just gobbledegook, and actually means something
Thank you, ill put my code in netBeans and do a autoformat! I am now getting these errors:
[code
TableTag.java:7: package MySite does not exist
]import MySite.*;
^
TableTag.java:13: incompatible types
found: javax.servlet.jsp.tagext.BodyContent
required: java.util.List
List list = body; // put bodycontent as list call text2list i wont need
^
TableTag.java:29: cannot resolve symbol
symbol : method getpricePassed ()
location: interface java.util.List
Iterator it = list.getpricePassed().iterator();
^
TableTag.java:32: package MySite does not exist
MySite.videoBean vids = (MySite.videoBean) it.next();
^
TableTag.java:32: package MySite does not exist
MySite.videoBean vids = (MySitet.videoBean) it.next();
^
5 errors[/code]
The layout of my fpackages is in jspwork i have a folder name MySite and another named beanTin inside beanTin is a folder named customTags where this class resides. Am i declaring the import wrong or are my packages not in the right places?
> Thank you, ill put my code in netBeans and do a
> autoformat! I am now getting these errors:
>
> [code
> TableTag.java:7: package MySite does not exist
> ]import MySite.*;
the package MySite indeed does not exist as far as the runtime is concerned. if you disagree, either you've mistaken "class" for "package" or you haven't included that package in your runtime classpath
> TableTag.java:13: incompatible types
> found: javax.servlet.jsp.tagext.BodyContent
> required: java.util.List
> List list = body; // put bodycontent as list call
> text2list i wont need
you're guessing at stuff again!
> :29: cannot resolve symbol
> symbol : method getpricePassed ()
> location: interface java.util.List
> Iterator it =
> list.getpricePassed().iterator();
like the compiler says, java.util.List doesn't have a getPricePassed method. I'd be overwhelmingly surprised if it did
> MySite does not exist
> MySite.videoBean vids = (MySite.videoBean)
> it.next();
see first point
> a:32: package MySite does not exist
> MySite.videoBean vids = (MySitet.videoBean)
> it.next();
and again
you're really asking for trouble by soldiering on this far without learning the basics. I wasn't just making that up to sound wise
Like i said this code is just me getting a feel for customtags with a body, i already have a piece of code that works and am now trying to put it into a custom tag.
How do i add MySite to runtime classpath? is that the same classpath i get to through control panal which as the location of the jdk in it? if so do i just put the ful path name eg c:\...MySite ?
Your code above has serious, serious syntax and concept errors.
And you clearly do not even understand the errors, or the error messages.
>
> i already have a piece of code that works
>
Then clearly someone wrote that code for you.
(Or other volunteers painstakingly corrected each line for you...)
Please stop. You are not going anyway if you continue this way.
> Like i said this code is just me getting a feel for
> customtags with a body, i already have a piece of
> code that works and am now trying to put it into a
> custom tag.
yeh, I get that. but you're not ready for it yet, you really aren't. you're not going to get a feel for anything, you're going to end up with some code written mostly by other people, that you don't understand, and works by coincidence. no use at all as an exercise. why bother getting the feel for something relatively advanced before you've got a feel for the implementing language? what you're trying to do is the code equivalent of learning Latin by writing a fifteen-volume novel and accompanying opera in it. slow down!
> How do i add MySite to runtime classpath? is that the
> same classpath i get to through control panal which
> as the location of the jdk in it? if so do i just put
> the ful path name eg c:\...MySite ?
a question you shouldn't need to ask if you're writing servlets and the like. you're no different from the rest of us, you need to get an understanding of the language before you go stampeding off learning all manner of libraries and other technologies. no point doing that without a solid foundation
until you've got the basics, every time you hit a problem, you'll be here asking for help, and getting all frustrated. I don't just spout this cr@p for a laugh, you know, it is actually true!
checky git lol no i wrote it myself! I had 2 errors with it one i did myself the other was a stupid mistake (calling a mthod on a wrong varaible!) Can somebody confirm how to add MySite to the runtime classpath? is it the ame class path i mentioned above?
you need to step back and do some more fundamental excercises. yeh, we can tell you how to fix this problem, but you won't - despite what you might think now - understand why it's a fix. I've seen you post a fair few questions here recently, most of which would not be asked if you just studied the basics a bit more. you need to learn how to read compiler output, and stack traces. nothing, nothing will accelerate your learning and your productivity more than that. the compiler output is incredibly useful as soon as you realise it isn't just gobbledegook, and actually means something
> checky git lol no i wrote it myself!
Prove it. Explain this error from your code:
> TableTag.java:13: incompatible types
> found : javax.servlet.jsp.tagext.BodyContent
> required: java.util.List
> List list = body; // put bodycontent as list call text2list i wont need
> checky git lol no i wrote it myself! I had 2 errors
> with it one i did myself the other was a stupid
> mistake (calling a mthod on a wrong varaible!) Can
> somebody confirm how to add MySite to the runtime
> classpath? is it the ame class path i mentioned above?
http://java.sun.com/docs/books/tutorial/java/package/managingfiles.html
Prove it. Explain this error from your code:
> TableTag.java:13: incompatible types
> found : javax.servlet.jsp.tagext.BodyContent
> required: java.util.List
> List list = body; // put bodycontent as list call text2list i wont need
I didnt write it as a tag i wrote it as a scriptlet and am now trying to put it into a custom tag! this being the first time i have used bodycontent i would image like it says the types are not compatiable list is expecting body varialbe to be of type list but i have body set to getBodyContent(); so there is obviously a mismatch of types
I have set the class path how it says but still am getting the same error, i set classpath to look in both the jsp/MySite and the Mysite where the classes are kept under tom cat.
[nevermind. comment deleted since the OP doesn't listen anyway]
point being? bodycontent as 3 main methods one to return the jsp writer one for that can read a tags body and another returns a string which contain the tag body I nenver claimed to write the libary! i said i wrote some code (get a list put it ito a a table) i am not trying to take that code and put it into a custom tag so instead of writing that code wach time i can pass in a list and have a tag sort it into a table i didnt realise this would cause such a big discussion and accusations who knew java could cause so much agro!
[snip]> who knew java could cause> so much agro!Indeed.
tsitha at 2007-7-21 20:07:26 >

If you use sensible variable names, proper indentation and other good coding practices, it could help you eliminate lots of problems.
The compile error or runtime error messages always tell you what went wrong, so you need to learn the meaning of the error messages and what action has to be taken.
rym82a at 2007-7-21 20:07:26 >

my problem at the moment is getting this classpath working, my class path now goes to the jsp/MySite and to the tomcat classes/MySite but when i import MySite i still get a message saying MySite package does not exist
have you read reply #11 ?
rym82a at 2007-7-21 20:07:26 >

Don't bother. The OP doesn't care to understand "how" to fix errors.He only wants exact instructions ("change this line to say this, and everything will work, no questions asked!")
> my problem at the moment is getting this classpath
> working,
No, your problem at the moment is the same problem you've been having since you've started posting.
You need to figure out the basics or you'll never be able to do anything
without asking these sorts of questions.
Of course, this is a waste of energy since you've been told this several times. You've also been given links to
tutorials which answer all your questions, you just don't care to read them.
tsitha at 2007-7-21 20:07:26 >

Yeah i read number 11 this is the last two bits added to classpath
D:\Documents and Settings\KevSmit\Desktop\work\Java Stuff\\ServletDistribution\jspwork\MySite;
D:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\MySite;
@Kathy I think asking a question pretty much implies i want to know "how" to fix errors! I don't just post " hay so and so don't work.....bye!" and i'm guessing the answer will be in the form of an instruction and yes an exact instruction of why my classpath is not working would help in this situation somebody replying " just mess with it for 2 hours" will not really help here.
Anyway you keep popping in with your comments and having your 15 minutes, its bumping up my thread so its only helping me more.
> Anyway you keep popping in with your comments and
> having your 15 minutes, its bumping up my thread so
You seem to think this is a hostile thing.
That we are beating you down, or claiming holier-than-thou.
>
> its only helping me more.
>
I want to help you. We are using direct suggestions, we are using
reverse psychology, we are using every tricks we can think of.
i'd rather you use the trick of "hes showed us is classpath, he read how to set it, its still not working lets tell him whats wrong" forget about the errors i'll sort them i just want the classpath working, i never said this was a hostile thing i just think it s a sorry state of affairs when i post in a new to java forum and want to set a classpath but need to go through 20-odd posts without a even so much as a helpful hint! (apart from who ever sent me to that page lol but that aint worked lol)
i'll try reverse psychology then.. i don't want to know how to set my classpath lol
Message was edited by:
eastenders
Why do you add "lol" everywhere? You sound like a 10 year old.
And your Java skills suggest likewise.
Anyway, others who are more patient than me will continue to try to guide you.
And I don't mind that your thread gets bumped up. (In fact, you can do it yourself,
just edit one of the message you previously posted, then that will bump the whole
thread up.)
Good luck in your life, and everything.
oo personal now! i could point out that lol is actually a dutch word meaning fun, or we could talk for hours about how terms like lol and brb are runing english, or i could point out by saying"you sound like a 10 year old" you sound like a typical forum user hiding by the anonymity of the internet and how that may point to some insecurities you have within yourself.
but i won't do that i'll just ignore you and up somebody as replied with a good answer. but btw if i was 10 i would be very proud of my java skills!
*sigh*
I don't care about you psychoanalyzing me.
I'm just pointing out that, in a professional setting, you should
capitalize the first word of your sentences, and use complete words.
That's all.
Look at the more professional questions on this forum. They have detailed
rationales; they're asking a specific issue with Java library that somehow is
causing them problem; they already tried several approaches (and they tell you
what approaches they tried, so that we volunteer helpers don't have to guess).
etc. etc.
> but i won't do that i'll just ignore you
Be as that may. I'll do you one more favor by bumping up this thread
one more time. Good luck.
Now that my Java and gramma skills (I didn't know this was getting graded!) have been under attack can we PLEASE get back on topic, I have added the package MySite to the the class path I have also added the package MySite from the tomcat folder to my classpath but it still says MySite package does not exist. Can anybody help me with this?
[snip]
> I have added the
> package MySite to the the class path
No you haven't. You're one directory too low - and if you'd read any of the material you've been given you'd know this.
> I have also
> added the package MySite from the tomcat folder to my
> classpath
no you haven't, and why did you think you should do this anyway? If
it didn't work above then how would this help you? Even if it
magically worked how would you know how to really do it? Would you
just add everything you could think of from here on out?
> but it still says MySite package does not
> exist. Can anybody help me with this?
As much as we try, I don't think so.
tsitha at 2007-7-21 20:07:26 >
