Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

toString(DELIMITER) problem

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the following bit of code in my repository class.. its meant to load variables in the restaurant class

my delimiter code in my restaurant class is

when i try to run my project and input some variables the text file i have created is vacant..

i have a store method as seen below in my DAOImpl class
 
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

IS the print method called or is there an exception?  Add a call to the printStackTrace method in the catch block to see if there is a error.


Also add a print statement just before the call to the print statement that prints out the String that the code is trying to write to the file so you can see if the code is executed.
 
Marshal
Posts: 24950
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Georgios Adamidis wrote:my delimiter code in my restaurant class is...



However what you are writing to the file is produced by the toString(delimiter) method of a Repository object. Consider looking at that code instead.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Georgios Adamidis wrote:my delimiter code in my restaurant class is...



However what you are writing to the file is produced by the toString(delimiter) method of a Repository object. Consider looking at that code instead.


my toString delimiter method in my repository class is as follows
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was printed on the console when you made the changes I suggested?  Was the print method called?  What was in the String that it was supposed to print?
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:What was printed on the console when you made the changes I suggested?


i dont really understand how to do that.. sorry im a complete noob
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add this statement just before the call to the print method:


Add this statement to catch block
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Add this statement just before the call to the print method:


is this meant for the DAOImpl class? I added it but to no avail.. i only get "printing"


Add this statement to catch block


where is this meant to go? restaurant controller class or the restaurant class where the variables are? EDIT: i tried adding it but i get a "cannot find symbol variable ex" error code
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

where is this meant to go?


That should go inside of ALL catch blocks so that any exception causes a full error mesage to be printed.

i get a "cannot find symbol variable ex" error code

Replace ex with the name of the exception variable that is passed to the catch.  ex was used on line 5.  Change to match the code.

Change this statement by adding an ending "<" to show how many spaces were printed, if any
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

where is this meant to go?


That should go inside of ALL catch blocks so that any exception causes a full error mesage to be printed.

i get a "cannot find symbol variable ex" error code

Replace ex with the name of the exception variable that is passed to the catch.  ex was used on line 5.  Change to match the code.

Change this statement by adding an ending "<" to show how many spaces were printed, if any


concerning the printing it prints "printing <" and concerning the ex.printStackTrace(); i still get a "cannot find symbol symbol ex" error code
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

cannot find symbol symbol ex"


Do not use ex.  Use the name that is in the catch block:


it prints "printing <"


Post the code for the toString method from the Repository class that is called in the store method on line 3
That print out shows the toString method is returning an empty String.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

cannot find symbol symbol ex"


Do not use ex.  Use the name that is in the catch block:


it prints "printing <"


Post the code for the toString method from the Repository class that is called in the store method on line 3
That print out shows the toString method is returning an empty String.


i added the ex but no result.. my repository toString code is as follows
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the code and see Why the toString method returns an empty String?  Is there another version of the class with a toString method that returns an empty String?
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Look at the code and see Why the toString method returns an empty String?  Is there another version of the class with a toString method that returns an empty String?



my restaurant class code is
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Look at the code and see Why the toString method returns an empty String?  Is there another version of the class with a toString method that returns an empty String?


or it might be a problem with my repository.store method? this is what i have
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem we were looking as was why this method call: repository.toString(DELIMITER) returns an empty String.  
The print statement: System.out.println("printing " + repository.toString(DELIMITER) + "<");
Printed this:   "printing <"
Which shows that an empty String was returned?

How can that happen?

You will have to post ALL of the code so it can be compiled and executed for testing.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:The problem we were looking as was why this method call: repository.toString(DELIMITER) returns an empty String.  
The print statement: System.out.println("printing " + repository.toString(DELIMITER) + "<");
Printed this:   "printing <"
Which shows that an empty String was returned?

How can that happen?


maybe it is a problem with the rest of the repository code?
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code shows where the empty String is coming from.  Line 63:
If the loop does not execute, the method will return an empty String.

The earlier code was different.  It showed an initial value in output in several posts.

Add a print statement just before line 63 that prints the value in items to see what it has.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:That code shows where the empty String is coming from.  Line 63:
If the loop does not execute, the method will return an empty String.

The earlier code was different.  I showed an initial value in output.


I've tried
but it only prints "Restaurant: " for some reason the loop isnt running can you maybe help with this?
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is in items?
Add a print statement just before line 63 that prints the value in items to see what it has.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:What is in items?
Add a print statement just before line 63 that prints the value in items to see what it has.


the rest of the code is as follows
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is in items?
If nothing is ever added to items, it will be empty.  

Make sure the code does something to add some value(s) to items.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:What is in items?
If nothing is ever added to items, it will be empty.  

Make sure the code does something to add some value(s) to items.


how can i do that?
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how can i do that?


What is the program supposed to do when it is executed?  Is there some time or place that something should be added to items?
If nothing is supposed to be added to items, it can be removed from the program because it has no purpose in the program.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

how can i do that?


What is the program supposed to do when it is executed?  Is there some time or place that something should be added to items?
If nothing is supposed to be added to items, it can be removed from the program because it has no purpose in the program.


when its executed it does the following

even though i get an error "incompatible types String cannot be converted to list restaurant.. so i press "n" to escape this issue and then the following gets triggered
which is where i decide which variable to modify and add the input into the variable.. im guessing that something needs to change in the first bit of code?
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i get an error


Please copy the full text of the error message and paste it here. It has important info about the error.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

i get an error


Please copy the full text of the error message and paste it here. It has important info about the error.



the code is from the RestaurantController class by the way.. the full error code is "incompatible types: String cannot be converted to List <Restaurant>"
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

incompatible types: String cannot be converted to List <Restaurant>"


The source code reference was left off.  Where does that error happen?  What line in what class?

For example:
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

incompatible types: String cannot be converted to List <Restaurant>"


The source code reference was left off.  Where does that error happen?  What line in what class?


RestaurantController class the error is on line 7

 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

incompatible types: String cannot be converted to List <Restaurant>"


The source code reference was left off.  Where does that error happen?  What line in what class?

For example:


The error message should show the source line number and the source code with the error.
See the above
error on line 1630 in TestCode25
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

incompatible types: String cannot be converted to List <Restaurant>"


The source code reference was left off.  Where does that error happen?  What line in what class?

For example:


The error message should show the source line number and the source code with the error.
See the above
error on line 1630 in TestCode25



Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: repositories.Repository.<init>
at controllers.RestaurantController.<init>(RestaurantController.java:26)
at restaurantapp.RestaurantApp.run(RestaurantApp.java:22)
at restaurantapp.RestaurantApp.main(RestaurantApp.java:34)
Java Result: 1
restaurantcontroller java error line


restaurant app problematic lines
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the current version of the Repository class have a constructor that takes a String as argument?
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Does the current version of the Respository class have a constructor that takes a String as argument?


here is my repository class with the toString ommited
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Does the current version of the Repository class have a constructor that takes a String as argument?


I do not see where you answered this question that I asked.
You need to look at your code and see what arguments the constructors take.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

Does the current version of the Respository class have a constructor that takes a String as argument?


I do not see where you answered this question that I asked.
You need to look at your code and see what arguments the constructors take.


no it doesnt have a constructor with a string as an argument
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then this line should have a compiler error:


You need to fix all compiler errors BEFORE trying to execute/run a program.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Then this line should have a compiler error:


can you tell me how to fix the restaurant class loop in the repository? maybe i can somehow trigger the items through the restaurantcontroller class?
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how to fix the restaurant class loop  


Execute the code that adds sometime to the items list.
 
Georgios Adamidis
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

how to fix the restaurant class loop  


Execute the code that adds sometime to the items list.


I dont understand what you mean..
 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at line 40.  It adds something to items.
Also look at lines 20, 25 , 30 that change the value in items.
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!