This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

location variable accessed from inner class needs to be declared final  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am listening user location and trying to do a distance calculation based on a longitude latitude value that i am pulling from database.The problem is i cannot access location.getLatitude() because compiler says me that i need to declare location final.But since its changing i cant do that.



 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

compiler says me that i need to declare location


Have you tried that?  What happened?
Where in the posted code is the value of location (the arg to the onLocationChanged method) changed?
 
yunus emre güney
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

compiler says me that i need to declare location


Have you tried that?  What happened?
Where in the posted code is the value of location (the arg to the onLocationChanged method) changed?



I cant write Location final location
 
Marshal
Posts: 63381
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That appears to be Android code, so I shall move you to our Android forum.

Yes, local variables used in a local class, or in Java8+, in a λ must be “effectively final”. In Java7 and apparently in Android too, that means you need to use the final keyword. In Java8+ you can get away with never reassigning the local variable; in fact the compiler error you are seeing wouldn't have occurred in Java8.
Please don't use screenshots to post your code.
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I cant write Location final location


Why not? Please explain what the problem is.

Did you try if?  What happened?


Note: the final keyword goes before the type name: final Location
 
Let's get him boys! We'll make him read this tiny ad!
ScroogeXHTML 8.2 - easy to use RTF to HTML converter library
https://coderanch.com/t/707504/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!