Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Type Mismatch

 
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:


 
Bartender
Posts: 4001
156
  • 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
 
Marshal
Posts: 69806
277
  • 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: 69806
277
  • 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?
 
Sheriff
Posts: 4870
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you the Bruce Banner? How exciting!
 
Campbell Ritchie
Marshal
Posts: 69806
277
  • 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.
 
Greenhorn
Posts: 15
Mac Netbeans IDE Java
  • 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: 69806
277
  • 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 …

 
    Bookmark Topic Watch Topic
  • New Topic