This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

dialog box with final info in it

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone help me in letting me know what is wrong with a part of my code....the following is the bottom of my code and i am trying to have a dialog box pop and have info in it. so here is my code:

 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok forget the above i fixed a few of those problems but i am getting two erorrs saying this:

operator > cannot be applied to java.lang.String,java.lang String if (user1age > user2age)

and i get the same thing for the less than sign as well.

anyone know why this is happening?
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Holly,

There are two compilation errors in your code, otherwise it works fine. The first one is a common beginner error (2nd line, not including comments) that you should get used to finding and resolving as it won't be the last time you do it. The second is a careless typo (2nd to last line not including comments). Slow down and pay attention when you're typing - you'll save yourself time later.

What does the compiler tell you is wrong and where (what line) is it telling you that the problem is on? Can you see anything that isn't as it should be? If you're really struggling, try commenting out complete statements or blocks of statements and see if the compilation error goes away. If, after trying hard to work it out, you're really stuck then post your code fragment on JavaRanch as you have done but be specific about what your problem is, i.e. my code won't compile: here's the error I get, here's my code, this is what I've tried.

If you help us we'll help you. I tidied up your code a bit but I've decided not to give it to you as I don't think it'll help you learn at present.

Jules
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this is what I mean by not posting until you really need help. I've wasted my time trying to help you with something you weren't really stuck with. What do you think the new error message means? How do you think it might be possible to get round it? If you can't compare Strings, what could you compare? If it makes your head hurt then I know the feeling but the effort is worth it.

As I recommended to someone else in another thread I think you'd benefit from going back over some of the basics of learning Java. Do you have course notes or a tutorial or a good book or something? Take things in small steps and grasp the basic concepts. Your question is a basic one even for the beginner forum.

I don't want to discourage you; I'm just trying to save you some pain.

Jules
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh thank you so much for helping me out. I am very excited you say it works, but not so excited I cant get it to work. I am trying to find those problems you were telling me about but i dont see it. im gunna keep looking some more, but in the mean time did you see the part above about the two errors i was getting? thanks again for all your help ill keep looking for those two mistakes.
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've fixed the mistakes I mentioned (I think) that's why you're seeing the other errors. Here's a useful tip that you may not be aware of: always fix the first error in the list that the compiler comes up with first. Sometimes if you fix the first error it makes all the other ones go away. Cool, huh? If you try and fix the second or subsequent errors without fixing the first you may well be wasting your time as they may not be errors at all! Always, always, ALWAYS fix the first error first.

Jules
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im really sorry i made you waste your time...i really dont understand why i am getting the errors and i have three books and class notes but for some stupid reason i cannot figure it out and can't see it and that is why i was asking for help. i guess ill just keep reading and hope i get it. again thank you for the help and i am sorry.
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just wanted to say thanks again you are very helpful and extreamly nice i appreciate it. a beginner needs people like you
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, the reason that my little piece of test code works fine is that I use the right data type for the age. Here it is, see if this helps you:

With regard to your books, etc., my advice is to start at the beginning and make sure you understand each bit as you go along. Once you've done that, go through it a second time and it'll all be much clearer. The basics are really important. Without a good grasp of the basic concepts you're really going to struggle with the trickier stuff. It's time well spent.

Jules
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok ok ok i got it to work....but wait here is my code:



ok the final dialog box i want it to look like this:

First Person: Smith, John (31)
Second Person: Doe, Mike (35)
Doe is older than Smith

I thought I had my code written to look like that, but i dont i guess I dont. Do i need to change something at the bottom where I compare?
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i just read your reply ill look through that
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The last part's easy. You shouldn't need any help with it.

Jules
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i am getting an error saying ; is expected and is pointing to the if and else statements...i know i should know this but does have to do with the way i am writing the message? or with the whole string message together?
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see what you're doing but there's nothing wrong with the code you posted above. The compiler normally points you to exactly where it is expecting a semicolon. My advice is to stick a semicolon there (usually the end of a line) and see if it compiles. If not, or if it compiles but doesn't behave as expected try commenting out the lines of code either side to see if that helps. You may also find it easier, as a beginner, to get into the habit of coding your if/else statements as follows:

Putting the curly brackets (braces) in can help save you some pain further down the line when you want to add code to the if statement. I don't know if that's your problem. Probably not. You've probably just left the ; off the end of your message string initialisation (total guess).

Jules
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jules!! Thank you so much for all the help today! You are awesome. I have the program working like a champ!! Thank you soooo much. I am sure I will be back on here in the next few days for more help, but I now know how to ask for it and make everything a little less confusing. Thanks again you helped me so much!

Holly
 
reply
    Bookmark Topic Watch Topic
  • New Topic