• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type Mismatch  RSS feed

 
Bruce Banner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to java and I'm doing problems to get better. I'm trying to make a puzzle that gets the user input and moves the rows either to the left or right, the columns move either up or down depending on what the user wants. The problem I'm getting is a type mismatch for my RL method which moves the rows to the left.


output I'm getting:
1 -2 1 0 0
-1 0 4 2 0
0 -4 1 -1 0
0 1 -1 -1 -2
0 -3 1 -1 0



Output I want if the user wants to move the first row:
-2 1 0 0 1
-1 0 4 2 0
0 -4 1 -1 0
0 1 -1 -1 -2
0 -3 1 -1 0


Error message:


 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Bruce,

you don't show us what the exact error is, and on what line it occurs. It is very helpful
to show us the full error message. Just copy the error message and paste it in your question..

But take a look at line 94. Variable 'board[j]' is an array of ints (to be more precise:
a pointer to an array of ints). The variable 'first' is an int (line 85).
So in effect, you try to assign an integer to an array.

If you use a 'two dimensional' array like in 'new board[5][5]', then the first dimension
is an array of pointers to other arrays. So, board[0] is a pointer to an array of
(in this case) 5 integers. Evenso board[1], et cetera.

Greetz,
Piet
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and welcome to the Ranch
 
Bruce Banner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put the error message
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That tells us you are using Eclipse and did what you shouldn't: run code with a red error mark on. You are using an array when you should have a number or vice versa. It should give you a line number (95), or you will have to look for the red mark. If you hover your mouse over the red mark you will get suggestions for corrections. They may not all be right.
 
Bruce Banner
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the red error mark located in eclipse?
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you the Bruce Banner? How exciting!
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bruce Banner wrote:Where is the red error mark located in eclipse?
Just to the left of the offending line.
 
Amir Al Take
Greenhorn
Posts: 15
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code there's a big mistake that you are making. In your RL method you assign value to broad which is one dimensional array. However in the parameters of your RL method you have declared board as two dimensional array. Another mistake that you make is that when you use board as one dimensional array you leave the other dimension totally. Thus it contradicts.

So if you want to assign value to your board array you need to do it like this:

board[indexA][indexB] = value;

Where indexA is first dimensional index and indexB is the second dimensional index.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Are you the Bruce Banner? How exciting!
The Link Given wrote:Bruce Banner, a socially withdrawn and emotionally reserved …
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!