• Post Reply Bookmark Topic Watch Topic
  • New Topic

switch default problem  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, how are you doing?

My name is Guilherme, i'm from Brazil and i'm new around here =)

I'm having problem using switch... the Default just doesn't work
Can anybody help me out?

code bellow


ps. i'm not sure if the code will be readable here... if not i'm sorry
 
Bartender
Posts: 1838
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the Ranch!

When Posting code you can UseCodeTags. (There is a button for it). I've added them to your post for you.
The only thing with it is that if you put code tags around something, you can't highlight part of it, so I have replaced your bold text with a comment to indicate where you thought the problem was.

I can't see anything obviously wrong with your switch statement.
What makes you think it is not working?
What happens when you run it?
Are there any error messages?
 
Marshal
Posts: 56600
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Why are you using option panes for input; that is very old‑fashioned style.
Don't write == false or == true. Not
if (b == true) ... but if (b)...
Not
while (b == false)... but while (!b)...
Using == is poor style and error‑prone; you might write = by mistake.
 
Guilherme Waldelm
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys thanks for the tips =)

default doesn't work... it simply doesn't do anything... if i press 6 for example (which is not an option in my switch) it won't pop up the screen with error message i created... the screen blink very fast but don't pop up anything.
There is no error message or something... and the other options are working fine
I'm not sure if my understanding of switch is right though... but for what i understand if i press something else like 7, that message will pop up. right?


I'm using joptionpane bcs is how my teacher is teaching us for now =P i started with java like... 1 month ago.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option Pane works, but it is very old‑fashioned; most people would use a Scanner nowadays.

What a strange error. Please post the whole of your code so we can try it and see if we can reproduce the problem. I cannot see the cause for any errors in the code you posted.
 
Guilherme Waldelm
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i found what's happening... i'm not sure how eclipse put this to my main


public static void main(String[] args, String ERROR, int messageType)


I took off " String ERROR, int messageType " and it Works.
what is this actually?

 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know how that got there; it looks like what you pass to create an SQLException. One of those little mysteries of life.
 
Ranch Foreman
Posts: 3068
37
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Don't know how that got there; it looks like what you pass to create an SQLException. One of those little mysteries of life.


Copy/paste error?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe. It is also possible to click on the wrong option. Eclipse can give you lots of options in a dropdown list and you can accidentally click the first option when you really want the third.
 
Guilherme Waldelm
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys =)

soon i will have more newbie questions for you hehe

but one day i will be the pro to answer too ;)
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guilherme Waldelm wrote:Thank you guys =)
You're welcome
. . .but one day i will be the pro to answer too ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!