• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using doubleToString

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers:
Am having problems with data type determination
and conversion.
I want to put all non double tokens into my name1 array and all doubles into data1 array.
CODE:

I get the following error message:
cannot resolve symbol
symbol : method doubleToString (double,int,int)
I got this method from Sun's page, but there's
not a whole lot written about it. Maybe I need an
example of it being used. Would appreciate
any advice. Thank you!
Pip
Edited by Dave to put code in code tags
[ February 12, 2002: Message edited by: Dave Vick ]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pip
Do you a have a method named doubleToString with the signature of (double,int,int)? It looks like the compiler can't find it.
You need to have the method in you class in order to call it.
 
Pip Vo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I decided to use a different converter:
name1[count2] = String.valueOf(data1[count1])
so my code is now:
import java.io.*;
import java.util.StringTokenizer;
public class catV2
{
static String temp1[] = new String[100];
static String name1[] = new String[100];
static double data1[] = new double[100];
static int count1 = 0;
static int count2 = 0;
static int i = 0; static int j = 0;
static int k = 0;
public static void main (String args[])
{
String line;

try
{
BufferedReader br = new BufferedReader
(new FileReader(args[i]));
while ((line = br.readLine()) != null)
{
System.out.println("CURRENT LINE: " +line);
StringTokenizer st = new StringTokenizer(line);
try
{
while (st.hasMoreTokens())
{
data1[count1] = Double.parseDouble(st.nextToken());
System.out.println("DATA: " +data1[count1]);
count1++;
j++;
} // end while
} // end inner try
catch (NumberFormatException e)
{System.out.println("ERROR: NOT DOUBLE");
//name1[count2] = double.toString(data1[count1]);
name1[count2] = String.valueOf(data1[count1]);
System.out.println("NAME: " +name1[count2]); count2++;}
count2++;
k++;
//}
} // end while
} // end try
catch(IOException e)
{System.err.println("ERROR: " +e);}

}
}
This compiles fine, but gives me weird results.
My sample file content:
123 ABC111
456 DEF222
789 GHI333
GR8 111111
Results:
reisling>>javac catV2.java
reisling>>java catV2 text.txt
CURRENT LINE: 123 ABC111
DATA: 123.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: 456 DEF222
DATA: 456.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: 789 GHI333
DATA: 789.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: GR8 111111
ERROR: NOT DOUBLE
NAME: 0.0
Why is 123 not a double? Please help. Thank you.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pip
the value 123 is an int not a double to make it a double change the file to be 123.0 and that should take care of it for you, the same for the other numbers in the file.
Also, when you post large sections of code please enclose them in the ubb code tags - see this page for more info on them.
 
Pip Vo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave:
Thanks. I changed my file to 123.0, 456.0, etc.
but still get wrong results (ERROR: NOT DOUBLE). This is driving me crazy.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like the program has no problem converting "123" into a double - that isn't what it's complaining about. The problem is the ABC111 afterwards - you try to convert that to a double, and can't.
One hint is - when you get an exception, print out the exception itself (not just "ERROR: NOT A DOUBLE"). This will often have additional information which will better explain the problem for you. In this case, it will tell you what the text is which it can't convert to a double.
 
reply
    Bookmark Topic Watch Topic
  • New Topic