+ 1

Java Prints Address instead of String

Hello, so I have a Class with a String in and a Method in the class which I call from my main class. The String gets returned by the Methode. But if I print it out I only get the address and not the String. I tried stuff like .toString but I just started and dont really know how to print it directly. Maybe someone can helpf

24th Nov 2021, 8:57 PM
Typischbaer
Typischbaer - avatar
22 Respostas
+ 5
We can help you, when you link your actual code so that the can see it!
24th Nov 2021, 9:05 PM
Lisa
Lisa - avatar
+ 3
I am a little reluctant to click on such links. Maybe you can post it in the news feed and link it here? You can save code on sololearn playground: go to code section, click the little +, select script language, insert your code, save, come here and link it.
25th Nov 2021, 9:34 AM
Lisa
Lisa - avatar
+ 3
You use the web version? A minimal working example would be helpful...
25th Nov 2021, 9:51 AM
Lisa
Lisa - avatar
+ 3
What does the ExampleMaze class look like? Does it have a get method for the maze string? Because I don't think .valueof() does what you want
25th Nov 2021, 10:24 AM
Lisa
Lisa - avatar
+ 2
Hello Typischbaer using toString() is correct but if you are writing an own class and want to use toString() you need to override it. Hope this code helps you to understand your problem: https://code.sololearn.com/cK2H7CdVEq45/?ref=app
25th Nov 2021, 3:39 PM
Denise RoƟberg
Denise RoƟberg - avatar
+ 1
new ExampleMaze(...) indicates another object type?
25th Nov 2021, 12:45 PM
Lisa
Lisa - avatar
+ 1
* You call the the maze from Examples.example01() * This returns an ExampleMaze which is derived from Maze and is constructed from a char array If I understand you correctly, you want to print out this char array (or string) To do that we would need to find out how this char array is stored in the ExampleMaze/Maze and how to access it. Right?
25th Nov 2021, 5:21 PM
Lisa
Lisa - avatar
+ 1
Denise RoƟberg From one of the snippets it looked like the char array is translated into a bitset ā€“ don't really know what it though...
25th Nov 2021, 5:31 PM
Lisa
Lisa - avatar
0
Sorry, I just was not sure in what way I can post stuff, because it is from university, and I am completly new and just try not to fuck up and learn. So here are some links, I got a library with a class of a Maze, you can see it in the picture and a methode that returns it. And in the third picture I am in the main class and I try to print it, but it only prints the Address. Like "de.blabla.blabla.examplesMaze@6237239edfs" https://ibb.co/qmNrR4w https://ibb.co/XSXYmW2 https://ibb.co/C2VSHsZ
25th Nov 2021, 9:28 AM
Typischbaer
Typischbaer - avatar
0
What do you mean with the news feed, where can I post it, I dont really use the platform besides the courses. And I cant really use the playground. Like I got the library from the university and cant really include that.
25th Nov 2021, 9:43 AM
Typischbaer
Typischbaer - avatar
0
For sure it would be. But like I said, its really hard for me right now, I try to understand and how to work with all the library I got from university, and I just wanted to start with printing the Maze that is createt, so I can have some visual Idea of what I have to work with and I cant even do that, and that is not even my task. I just would like to give you the possibility to look at it, but more than some screenshots are not really possible for me right now, if you have an idead where I can upload it on this platforms so you can look at it or somewhere else, I am open for that.
25th Nov 2021, 10:01 AM
Typischbaer
Typischbaer - avatar
0
Okay, so I have the class "Examples" in there are 2 Example mazes as strings and two integers with the with of each one. So 1. Widthexample 1, 2. example 1 "### ###..." (Maze represented with "#" and spaces 3. Widthexample 2 4. example 2 "## ##" They are declared as "private static final int/string Then a Method Maze example01 and also one with 02. In each of them it returns "return new ExampleMaze("### ##".toCharArray(), 13) 13 is in this the width of the Maze, on the other the number is diffrent. In the Main class, I try to call it with Examples.example01()
25th Nov 2021, 12:42 PM
Typischbaer
Typischbaer - avatar
0
Well there is another class calle ExampleMaze, as of what I understand this one is creating the Maze, but tbf I have problems analysing what it specifically does
25th Nov 2021, 2:17 PM
Typischbaer
Typischbaer - avatar
0
But an ExampleMaze is what holds the maze string and ExampleMaze is what .example01() returns? So we need to know how the maze string is stored inside the ExampleMaze class in order to access this string and print it, right?
25th Nov 2021, 2:25 PM
Lisa
Lisa - avatar
0
Okay so I copied a part of the ExampleMaze part, where I think the important information for the Maze is in a Playground thing. https://code.sololearn.com/c2g158qOm4L4 I dont think I cant provide you the information that you need
25th Nov 2021, 2:40 PM
Typischbaer
Typischbaer - avatar
0
Okay @Denise, thanks for sending it. So how I understand it ist, that I have to create the Object in my main class, and then get the Example maze from this Object? Like Example e1 = new Example() e1.example(01) (String in the Example class) But, how I thought how I would need to do it doesnt work, it doesnt give me the possibility to do like "e1.example(01)". It does not show up. Did I thought wrong?
25th Nov 2021, 4:36 PM
Typischbaer
Typischbaer - avatar
0
Typischbaer Just for understanding: You call this example01() method and it prints the address? So you need the return type of this method. Then look into the class of this return type. And if you are allowed to manipulate this class you need to override the toString() method in this class. But maybe the problem is easier to solve. Can you show is this example01() method?
25th Nov 2021, 4:55 PM
Denise RoƟberg
Denise RoƟberg - avatar
0
yes so what I exactly do is, "String map = Examples.example01() Examples is the Example class that holds 2 examples, and the 2 integers of the width. example01() is the methode in this Class. Here is one more link for just the class, will delete it later again https://code.sololearn.com/cRkhwVilr8Go Plus: I can not manipulate the Example class, which I send you.
25th Nov 2021, 5:17 PM
Typischbaer
Typischbaer - avatar
0
Lisa Yep. I think we need to look into ExampleMaze. And if this class works with arrays or returns arrays than it makes sense that it prints the address.
25th Nov 2021, 5:27 PM
Denise RoƟberg
Denise RoƟberg - avatar
0
Which statement are you using to print? printf System.out.println
26th Nov 2021, 2:58 AM
Pranay Sehgal
Pranay Sehgal - avatar