unexpected type.....why?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 6
Reputation: ming97 is an unknown quantity at this point 
Solved Threads: 0
ming97 ming97 is offline Offline
Newbie Poster

unexpected type.....why?

 
0
  #1
Oct 26th, 2008
Dear All,

I have a problem with Java Programming. I am writing a TatTicToe Program but I found a Error. It is a unexpected type for mark.equals("X")? currentPlayer=1: currentPlayer=0;

I don't know what happen. If you don't mind , I hope that All people will give some advises to this problem.

Thank you for your attention.

regards,
ming

The Detail of Execution Information :

init:
deps-jar:
Compiling 1 source file to C:\TicTacToe \build\classes
C:\TicTacToe \src\tictactoe \Server.java:242: unexpected type
required: variable
found : value
mark.equals("X")? currentPlayer=1: currentPlayer=0;
1 error
BUILD FAILED (total time: 7 seconds)
Last edited by ming97; Oct 26th, 2008 at 10:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 803
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: unexpected type.....why?

 
0
  #2
Oct 27th, 2008
You are using the value "X" in the .equals(Object) method which expects an Object as a parameter. It would be better if you declared your "X" as a constant String or char and compared the variable mark to that instead.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,649
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: unexpected type.....why?

 
0
  #3
Oct 27th, 2008
> You are using the value "X" in the .equals(Object) method which expects an Object as a
> parameter.

Huh? Firstly, the equals method is overridden in the String class. Secondly, if a method accepts an Object, you can pass any reference type to that method.

The problem here is that `conditional operator' is incorrectly used.
  1. int currentPlayer = mark.equals("X") ? 1 : 0;
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 803
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: unexpected type.....why?

 
0
  #4
Oct 27th, 2008
Oops, of course you are correct SOS. Sorry for the blunder, wasn't thinking!
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 508 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC