• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mark cannot be converted to int  RSS feed

 
Danny Broadwater
Ranch Hand
Posts: 65
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using NetBeans IDE 7.4. I am getting an error on lines 33, and 36 stating - Mark cannot be converted to int. Can you please help me find a way to correct this. Here is what I have:

package Games.Board


package games.board



Thanks for your time, Danny
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error? A compile error? An exception?
Why not paste it here so we can see?
 
Danny Broadwater
Ranch Hand
Posts: 65
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Here is the error.



Thanks for your time, Danny
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The switch is on content - which is an int. What are CROSS and NOUGHT? Apparently of type Mark?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you get lines 33/36 sorted out and get the code to run, I am afraid, you will find lots of other errors at runtime.
Why are you setting a Graphics object to null?
Why have you get your own Graphics class?
You are not supposed to supply your own class. The Graphics object is provided by the runtime environment; whenever the Component appears or reappears, the runtime sends a Graphics object and calls that method. Never call paintComponent directly. And give paintComponent() protected access.
Get rid of the switch altogether. If you want any drawing, do that from inside the symbol object. Give the symbol a method to draw itself which takes that Graphics object as a parameter. Much more object‑oriented.

The compiler error means you told the switch you were sending it an int (choice) and sent it an enum element instead.
 
Danny Broadwater
Ranch Hand
Posts: 65
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CROSS and NOUGHT are X and O for tic tac toe. I built a tic tac toe game in text style, now I am adding graphical user interface.
Thanks for your time , Danny
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danny Broadwater wrote:CROSS and NOUGHT are X and O for tic tac toe.

You misunderstood; what type are they? Apparently Mark, and not int.
 
Danny Broadwater
Ranch Hand
Posts: 65
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are Mark. Danny
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you have switch on an int, but the switch cases are Mark - that does not compute. You probably want to switch on a variable of type Mark, but it's hard to tell what's going on, because right before the switch you're declaring "int content = 0". So it's not clear to me what that switch should be doing; it doesn't make sense to switch on something that has a fixed value, even if the types match.
 
Danny Broadwater
Ranch Hand
Posts: 65
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it would be better if I just start over and rethink what is going on. I thank you for your time and effort. Danny Not giving up just backing up and regrouping the thought pattern. Thanks again Danny
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some things to consider:

Line 16 of your first piece of code: Don't call your own class JButton. There's already a standard class called JButton. Using the same name as a standard class can lead to very confusing errors.

Lines 59-61: There's a standard, public toString method in class Object that you can override. But you have a private ToString method here. That looks very confusing. Did you mean to override toString? Then you should name your method here toString instead of ToString and make it public.

Lines 63, 69, 87: Why do you have your own classes Graphics, Graphics2D and BasicStroke here? Those are all names of standard Java classes; you should not give your classes the same name as standard classes, as I already said above. Why do you need these classes? Remove them and import the standard classes instead:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.BasicStroke;


Line 93: What is this class string for? Why do you need this?

Line 29 of your second piece of code: The variable 'ints' was initialized in line 24 to have 3 elements. Array indices are 0-based, so an array with 3 elements has indices 0, 1, 2. You are trying to access the fourth element (index 3) of an array that has only three elements. That indeed gives you an ArrayIndexOutOfBoundsException.

Where is your class Cell? What type does its getContent() method return?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!