Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problem with lambda expression

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have gotten the issue fixed, and here is what my solution was, now I run into another problem. lines 116 - 137
I am trying to use a lambda expression to perform all of my calculations, however, I have not yet been able to get the lambda expression to even work.
It keeps giving me an error line 116 stating that "e cannot be resolved to a variable", and also on that same line "Syntax error on tokens, ( expected instead"
I can post this to a different thread if this is straying off subject.
 
kennith stomps
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I go into adjust my java compliance level, the highest number is 1.7, however my library  in the build path is JRE System Library [jre1.8.0_161]  so I am using java 8, so that should not be a problem, however, the lambda expression is still not working
 
Saloon Keeper
Posts: 2623
329
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kennith stomps wrote:... the lambda expression is still not working


Do you mean the code does not compile?  What errors are reported?
 
kennith stomps
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The errors being reported are on line 116 and line 117
116 is "Multiple markers at this line
- e cannot be resolved to a variable
- Syntax error on tokens, ( expected
instead
- e cannot be resolved to a variable"

117 is "Syntax error, insert ")" to complete Expression"

when i compile the code I get this error
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Error: Unresolved compilation problems:
e cannot be resolved to a variable
Syntax error on tokens, ( expected instead
Syntax error, insert ")" to complete Expression
Syntax error, insert ")" to complete Expression
Syntax error on tokens, delete these tokens

at chap15EventDriven.CourseScoreLambda.start(CourseScoreLambda.java:116)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application chap15EventDriven.CourseScoreLambda
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in your previous thread you said you were compiling this with Java 8, but then you said something about Java 7. So make sure you're compiling with Java 8.
 
Marshal
Posts: 64710
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop trying to work out a λ amongst lots of other code. Write a separate program which compiles and evaluates the λ on its own, and only put it into your current code when you are confident it is working.

Also, your lines are far too long. Break those lines 116‑117 into smaller lines; you can probably get ten lines out of that code. You need to be able to read the code before you can work out what is going wrong.
I think you might be better off using this sort of λ:- xyzButton.setOnAction(e -> xyzButtonAction(e)); and writing a method to handle the action.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!