This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Operator + undefined  RSS feed

 
Wendy Thiel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have everything coded but am unable to get it to print.
The error it is giving me is "The operator + is undefined for the argument type(s) Sring, Void"



Just in case the problem is above here is the full code.


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your setorder, setitems and setboxes methods are void methods, which mean that they do not return a value.

Something like: "Order number is " + this.setorder(newValue) + ...

does not work, because setorder does not return a value that can be put after "Order number is ".

Either make your methods return the value to be concatenated, or solve the problem in a different way, for example by concatenating the value of a variable instead of whatever the method returns.
 
Ray mann
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is that you are not returning any thing to the caller println method. Below I have adjusted the code below ... Im not sure if that was all the code to the app but i modified it to work so feel free to edit it as you
like .

There are a few thing that seem odd in the code you gave:
why are you using doubles ?
why are you making so many variables that never get used?
you created setter methods but for got the getter methods.
you never create a object.



Think about what I mentioned above it will help. 
I hope this solves your problem if you have any questions or need any further help just ask. ;)
 
Ray mann
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my code replace this :

//warehouse has one constructor
StackStuff (double Startorder, double Startitems, double Startboxes)

with this :
//warehouse has one constructor
warehouse (double Startorder, double Startitems, double Startboxes)

then it will work for you !
 
Liutauras Vilda
Marshal
Posts: 4626
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Why the variable names start with an upper case? Probably better would be to follow standard convention 'variableName'.
2. Try to keep instance variables private by prefixing them with 'private' access modifier.
3. Try to avoid writing unnecessary comments. i.e.
better would be to replace with ([1] added private access modifier, [2] changed data type to int, [3] changed variable name, [4] removed redundant comment):
4. Class names supposed to start with an Upper case. Better that would read as 'Warehouse'.
5. Code formatting and indentation also could be improved significantly.
 
Ray mann
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All true, although I remember when had just started out in java I used to comment  a LOT as it would help me remember and understand what was what and sped the leaning process up.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!