weird runtime error

weird runtime error

Post by asbjorn » Thu, 29 Mar 2007 03:08:10


Hi. I'm currently taking a beginners java-programming class at the
University in Bergen, Norway. This week we got an assignment that we
have to do before friday. If I don't pass, they won't let me take the
final exam... :(
So we're making a sudoku game, and the teacher gave us a bunch of
classes. We're supposed to "fill in the blanks". It all went
reasonably well, until I tried to print out the sudoku table, and i
got this really weird output. Instead of numbers, I got this:
Region@112f614 (Region is the class of which the cells in the table
are objects - I think...) Does anyone know what causes this? If
needed, I could post the code, but it is a lot of code, and all the
comments and the names are all in norwegian. But if you need to see
the code in order to help me, please just ask.
 
 
 

weird runtime error

Post by Richard Re » Thu, 29 Mar 2007 03:12:10


add a method to your Region class:
public String toString()
{
return "however you want the output to look";
}
the "however you want the output to look" bit is likely to be something like
getValue() or getNumber, whatver your method is called in the Region class
that gets the output you actually want to see

 
 
 

weird runtime error

Post by Oliver Won » Thu, 29 Mar 2007 03:22:27


It's not an error. You are probably providing an instance of Region to
System.out.print() or System.out.println(). The implementation of
System.out.println() is to invoke the .toString() method on any objects
passed in.

The conceptually simplest fix would be to not pass an instance of
Region to System.out.println() at all, but rather to query the Region
objects for the information you wish to print out (e.g. the contents of a
specific cell), and print that out instead.

Another solution would be to modify the Region class so that it
overrides the toString() method.

- Oliver
 
 
 

weird runtime error

Post by asbjorn » Thu, 29 Mar 2007 04:17:57


Thakns a lot for the replies! :) I think I get it.