• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method is undefined for the Type  RSS feed

 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a problem with my code with Junit:
"The method infinityNorm(double[) is undefined for the Type Vektor."
This error pops up for both the euclidian norm and the manhattan norm.

Here is the code:


What is the problem here?
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't return null for built-in data types. If you change the return type to "Double" it will work but then any caller will have to handle a possible null return.
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You code as it is works as far as I can tell. That is, it compiles and I get some output.

You mention jUnit but include no examples of a jUnit test. Perhaps you've forgotten to post some part of your program that is trying to call 'infinityNorm'?
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You can't return null for built-in data types. If you change the return type to "Double" it will work but then any caller will have to handle a possible null return.


That part of the code is commented out and should be ignored as it is not finished yet.
My problem is with the already written methods.
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Von Valkenburgh wrote:
Carey Brown wrote:You can't return null for built-in data types. If you change the return type to "Double" it will work but then any caller will have to handle a possible null return.


That part of the code is commented out and should be ignored as it is not finished yet.
My problem is with the already written methods.
Well, your error message states that "The method infinityNorm(double[) is undefined for the Type Vektor." . So, if you've commented out this method then you'll get this error -- it's undefined.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Dennis Von Valkenburgh wrote:
Carey Brown wrote:You can't return null for built-in data types. If you change the return type to "Double" it will work but then any caller will have to handle a possible null return.


That part of the code is commented out and should be ignored as it is not finished yet.
My problem is with the already written methods.
Well, your error message states that "The method infinityNorm(double[) is undefined for the Type Vektor." . So, if you've commented out this method then you'll get this error -- it's undefined.


Ok let me repeat my initial post:
"This error pops up for both the euclidian norm and the manhattan norm."
Forget the infinityNorm, it doesnt exist right now. I get the same error for the already finished methods.
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Von Valkenburgh wrote:
Carey Brown wrote:
Dennis Von Valkenburgh wrote:
Carey Brown wrote:You can't return null for built-in data types. If you change the return type to "Double" it will work but then any caller will have to handle a possible null return.


That part of the code is commented out and should be ignored as it is not finished yet.
My problem is with the already written methods.
Well, your error message states that "The method infinityNorm(double[) is undefined for the Type Vektor." . So, if you've commented out this method then you'll get this error -- it's undefined.


Ok let me repeat my initial post:
"This error pops up for both the euclidian norm and the manhattan norm."
Forget the infinityNorm, it doesnt exist right now. I get the same error for the already finished methods.
Let's see your JUnit code that calls these methods.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to call infinityNorm from somewhere, and it's not anywhere in the code you've presented thus far.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:You're trying to call infinityNorm from somewhere, and it's not anywhere in the code you've presented thus far.

Like I said before: infinityNorm is commented out and is not active as of now because I have not worked on it yet.
Im talking about euclidian and manhattan right now.
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so you have some unit tests that are calling infinityNorm which is a method that doesn't exist because you have it commented out.

If you don't want to run those particular unit tests then you can add the @Ignore annotation to the test methods and jUnit won't run them.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Ok, so you have some unit tests that are calling infinityNorm which is a method that doesn't exist because you have it commented out.

If you don't want to run those particular unit tests then you can add the @Ignore annotation to the test methods and jUnit won't run them.


Again: I get the same error for manhattan and euclidian. Do you understand?
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand perfectly. None of your unit tests will run successfully because you have a compilation error in your test class.

(My previous comment about using @Ignore is nonsense, ignore that)
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Tim does understand. There is no need to repeat yourself. Tim has given you some useful advice; please follow it.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I apologize for the somewhat rash tone of my reply.
My teacher mispelled euclidian and manhattan in the junit tests so I had to correct for that error.
now all tests work perfectly!
Thanks!
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another question:
the isZeroTest0 returns an error for isZero([]) should be true. I assume it means a completely empty array.
How do I accomplish this in the code?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Von Valkenburgh wrote: . . .
the isZeroTest0 returns an error for isZero([]) should be true. I assume it means a completely empty array.
. . .
Please show us the exact code and the exact error message, but only for the parts of the code you are calling. Maybe your isZero method looks for 0s in an array and an empty array does not contain any 0s.

And … apology accepted
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already solved the isZero problem.
The test checked whether an array such as array{} would return positive, which it should.

I have one last question for the following code:


When I add up two arrays of the same length all is fine.
But when I add up arrays of different lengths, like one array with 2 elements and one array with 3 elements, it cuts off the last element of the logner array. For this I get an error in Junit.
How can I rewrite the method to keep any remaining elements that will not be part of the adding up?
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Von Valkenburgh wrote:I already solved the isZero problem.
The test checked whether an array such as array{} would return positive, which it should.

I have one last question for the following code:


When I add up two arrays of the same length all is fine.
But when I add up arrays of different lengths, like one array with 2 elements and one array with 3 elements, it cuts off the last element of the logner array. For this I get an error in Junit.
How can I rewrite the method to keep any remaining elements that will not be part of the adding up?

 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with
double sum2 = sum(array1) + sum(array2);

Something which is better implemented in a declarative style with Streams than the old imperative style with a for‑each loop.
Remember that doubles occupying a wide range will undergo overflow or underflow or not have the appropriate precision.
System.out.println(12345678901234567890.1234567890 + 99 == 12345678901234567890.1234567890);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!