Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 22nd, 2003, 08:28 AM
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to chikodi
Default casting double to String.


Why wouldn't the following compile?

out.println("<tr><td>" + (String)tokenizer.nval + "</td>");

Compiler message is "inconvertible types".


  #2 (permalink)  
Old October 22nd, 2003, 09:16 AM
Registered User
Join Date: Jun 2003
Location: , , Ireland.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

I'm guessing (since you don't mention what type of object the tokenizer is) that the tokenizer is a StreamTokenizer object. The tokenizer.nval is a double, so you are trying to cast a double into a String which you can't do in Java! Thats why you get the error message.
  #3 (permalink)  
Old October 23rd, 2003, 02:50 AM
Authorized User
Join Date: May 2003
Location: New Delhi, Delhi, India.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts

Please specify which Object does the tokenizer.nval contains.If it's an Integer or Double or Long you can use the toString() method of these class to get the String representation. If tokenizer has some primitive data type the u can use the

String.valueOf(double d);

parameter will change depending on the data type


Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Double Quotes from a string Durkee VB.NET 2002/2003 Basics 12 October 4th, 2007 12:10 PM
Casting String array to string Samatha ASP.NET 1.0 and 1.1 Professional 1 December 5th, 2006 07:46 AM
Casting System::Object __gc * to System.Double[] nepsat Visual C++ 3 November 19th, 2005 12:51 PM
String to Double conversion mkpriya VS.NET 2002/2003 3 October 21st, 2003 05:26 AM
double to string? chris97b Visual C++ 4 September 23rd, 2003 02:34 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.