my dog learned polymorphism*
The moose likes Beginning Java and the fly likes How to convert Long to String. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert Long to String. " Watch "How to convert Long to String. " New topic
Author

How to convert Long to String.

Preethi jaya
Greenhorn

Joined: Aug 18, 2008
Posts: 12
How to convert Long to String.

long locationId = 0;

while (rs.next())
{
locationId = rs.getLong("LOCATIONID");
LocationInfoHelper locationInfohelper = new LocationInfoHelper();
String localTime = locationInfohelper.getLocalTimeForLocation(locationId);
}

I am getting below error.

getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) in com.apr.swd.servlet.helper.LocationInfoHelper cannot be applied to (long)
String localTime = locationInfohelper.getLocalTimeForLocation(locationId);
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Ehhh ..Where are you converting 'long to String'?

The line that does not compile is locationInfohelper.getLocalTimeForLocation(locationId); and the reason is also pretty clear - the function getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) is defined with another set of parameters.

Are you coding for a web application? Are you using Servets/jsp?

Little more details about what you are trying to achieve please?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Fred Hamilton wrote:Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it


Sorry but I am not sure where you got this from? The signature of getLocalTimeForLocation is getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) -- requires a int and HTTPServletRequest object not a String.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Sam Mercs wrote:
Fred Hamilton wrote:Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it


Sorry but I am not sure where you got this from? The signature of getLocalTimeForLocation is getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) -- requires a int and HTTPServletRequest object not a String.


duly noted. I withdraw the comment "I'm guessing the function call locationInfohelper.getLocalTimeForLocation(locationId); wants locationId to be a string. " with apologies for a very careless remark.

However, the question was "How to convert a long to a String" at least my answer to that question is correct, although it is no longer clear why the question is relevant to the problem. Maybe the poster doesn't know the method wants an int?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

well,

in other hand , you can do like below

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
seetharaman venkatasamy wrote:well,

in other hand , you can do like below



or this...


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Anyway, you should avoid "new Long", "new Integer" and all others. Since Java 5.0 all of the primitive-wrapper classes have a static method called "valueOf" which takes a matching primitive, and returns a wrapper instance (e.g. Character.valueOf('a'), Boolean.valueOf(true), Integer.valueOf(4)). The advantage of using "valueOf" over "new" is that "valueOf" may return any cached objects.
For instance, Byte, Short, Integer and Long keep objects for all values between -128 and 127 in a cache. Character similarly has a cache for 0 to 127 (a.k.a. the ASCII characters), and Boolean.valueOf returns either Boolean.TRUE or Boolean.FALSE - static final Boolean objects that represent the only two choices.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert Long to String.
 
Similar Threads
convert a String to Long
Convert Local time to UTC and vice versa
JSTL Comparison Syntax
how to convert Byte to the String
Cannot Resolve Symbol: Calendar.getInstance();