Results 1 to 16 of 16
 04192008, 09:20 PM #1Member
 Join Date
 Mar 2008
 Posts
 32
 Rep Power
 0
Can't solve error message while looping
Finally after few posts and few attempts I have managed to read text file and out put it on the screen. The file has 60 lines of data in three columns. Every thing works until I try to read 1 row of three doubles for calculation. So when I had this:
Java Code:double[] gene={9.30, 5.65, 5.02}; double[] gene1={5.30, 3.65, 2.02};
Java Code:G:\Read File\csv.java:145: parseDouble(java.lang.String) in java.lang.Double cannot be applied to (java.lang.String[]) double ii = Double.parseDouble(myarray); ^ 1 error Tool completed with exit code 1
Java Code:import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.Writer; import static java.lang.Math.*; public class csv { public static void Manhattan(double[][] a,double[][] b,int n,int n2) { int q=n2; int c=n; for(int m=0;m<q;m++) { for(int h=0;h<q;h++) { double d=0; double d2=0; for(int j=0;j<c;j++) { d2=a[m][j]a[h][j]; if(d2<0) d2=d2*1; d=d+d2; } b[m][h]=d; } } } public static double Euclidean(double[] array1, double[] array2) { //Store the numbers of the both arrays double x1= array1[0]; double y1=array2[0]; double x2= array1[1]; double y2= array2[1]; double x3=array1[2]; double y3=array2[2]; //Compute the minus part of the formula double minusResult1 = y1x1; double minusResult2 = y2x2; double minusResult3 = y3x3; //Square the answers double square1 = pow(minusResult1, 2); double square2 = pow(minusResult2, 2); double square3 = pow(minusResult3, 2); //Sum the squares double sumOfSquares = square1+square2+square3; //Get the square root of the sumOfSquares double finalResult = sqrt(sumOfSquares); return finalResult; } public static double Manhattan(double[] array1, double[] array2) { //Store the numbers of the both arrays double x1= array1[0]; double y1=array2[0]; double x2= array1[1]; double y2= array2[1]; double x3=array1[2]; double y3=array2[2]; //Compute the minus part of the formula double minusResult1 = y1x1; double minusResult2 = y2x2; double minusResult3 = y3x3; //Square the answers double abs1 = abs(minusResult1 ); double abs2 = abs(minusResult2); double abs3 = abs(minusResult3 ); //Sum the squares double sumOfAbs = abs1+abs2+abs3; //Get the square root of the sumOfAbs double finalResult = sqrt(sumOfAbs); return finalResult; } public static double Pearson(double[] array1, double[] array2) { //Store the numbers of the both arrays double x1= array1[0]; double y1=array2[0]; double x2= array1[1]; double y2= array2[1]; double x3=array1[2]; double y3=array2[2]; //Compute the minus part of the formula double mean1 = (x1 + x2 + x3)/3; double mean2 = (y1 + y2 + y3)/3; double t = (x1  mean1)*(y1  mean2) + (x2  mean1)*(y2  mean2) + (x3  mean1)*(y3  mean2); //Square the answers double square1 = sqrt((x1  mean1)*(x1  mean1) + (x2  mean1)*(x2  mean1) + (x3  mean1)*(x3  mean1)); double square2 = sqrt((y1  mean2)*(y1  mean2) + (y2  mean2)*(y2  mean2) + (y3  mean2)*(y3  mean2)); //Get the square root of the sumOfSquares double finalResult = t/(square1*square2); return finalResult; } public static void main(String[] args) throws Exception { // Set file name & path String filepath = "Data_Set_1.txt"; //String output = "Output_Data_Set_1.txt"; // Read in file FileInputStream in = new FileInputStream(filepath); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Write file //FileOutputStream out = new FileOutputStream(output); //BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(out)); // Declare Array which will hold 61 lines String[] myarray; myarray = new String[61]; double ii = Double.parseDouble(myarray); // Read each line into the array for (int i = 0; i < myarray.length; i++){ myarray[i] = br.readLine(); } in.close(); // Print out array info in desired order. Delete " characters for (int i = 1; i < myarray.length; i++){ System.out.println(myarray[i].replace("\"", "")); } double[] gene={9.30, 5.65, 5.02}; double[] gene1={ii}; for (int i = 1; i < myarray.length; i++){ double EuclideanDist = Euclidean(gene, gene1); System.out.println("Euclidean distance = " + EuclideanDist); double ManhattanDist = Manhattan(gene, gene1); System.out.println("Manhattan = " + ManhattanDist); double PearsonDist = Pearson(gene, gene1); System.out.println("Pearson = " + PearsonDist); } } }
Java Code:9.30 5.65 5.02 4.10 5.68 0.56 4.75 0.11 2.86 1.54 10.01 1.99 6.29 5.62 2.78 13.02 1.31 1.61 5.85 3.79 6.56 12.71 0.45 0.62 3.05 12.65 5.07 2.18 5.82 9.73 1.74 0.99 3.66 7.88 0.93 8.33 6.34 1.85 4.00

It looks like you are tying to convert a String array to double. This is the wrong approach. You should convert each array element to double value and if necessary store it in a double array afterwards. Write a loop and convert each string value one by one in this loop.
 04192008, 10:46 PM #3Member
 Join Date
 Mar 2008
 Posts
 32
 Rep Power
 0
Thanks for taking interest but can you show me how to do that cos I have lost my brain trying to crack it.
 04202008, 07:03 AM #4
Yes, You can do that....
Try to convert the String elements in that String array to Double....
Not Array of String to Double.... Do you know about Java Core API docs?
regards,
sukatoa
 04202008, 08:19 PM #5Member
 Join Date
 Mar 2008
 Posts
 32
 Rep Power
 0
Dude if new that I would not be bothering you. Please show me how to do this. Please.
 04212008, 01:23 AM #6Java Code:
String data[] = {"1.1","2.2","3.3","4.4"}; Double converted[] = new Double[5]; int x=0; while(x<5){ converted[x] = Double.parseDouble(data[x]);x++; }
regards,
sukatoa
 04212008, 05:57 AM #7
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
 04212008, 10:41 AM #8Dude if new that I would not be bothering you. Please show me how to do this. Please.
Java 2 Platform SE 5.0Did this post help you? Please me! :cool:
 04212008, 06:43 PM #9Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
 04222008, 03:34 AM #10
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
Captain, Don, sukatoa,
Does anyone of you know an application where we can find all Java doc, APIs and so on. A link...! :)
 04222008, 04:18 AM #11Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
 04222008, 04:29 AM #12
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
Ah, application mean a program like MSDN. I seen such a tool one of my friend use. But he don't give any detail about it. :(
What I try to do is make a collection of APIs and Docs myself. :)
 04222008, 10:20 AM #13
Are you looking to write your own APIs & Docs? Have you read about the JavaDoc tool?
javadocThe Java API Documentation GeneratorDid this post help you? Please me! :cool:
 04222008, 10:35 AM #14
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
No Don, I'm not try to write my own stuff. I just want to make a collection. Say I'm working without a network connection, if I have a such collection no need to worried about :)
 04222008, 10:39 AM #15
Oh right... You want to download the entire API documents to your computer.
I think they are available for download but i'm not sure where they are. I cant seem to find them.
You could try software that downloads the entire contents of a webpage. Check google..Last edited by DonCash; 04222008 at 10:47 AM.
Did this post help you? Please me! :cool:
 04222008, 10:51 AM #16
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
:) Yes few softwares available which can we used. But the reason is, not possible to find all of them in a single place.
Similar Threads

How to solve "No compiler error"?
By iceman in forum New To JavaReplies: 5Last Post: 04222008, 03:37 AM 
java error message
By baileyr in forum New To JavaReplies: 2Last Post: 01232008, 04:47 AM 
Help mi solve my error
By Deon in forum New To JavaReplies: 3Last Post: 01112008, 06:26 AM 
Help with error message when running JAR via HTML file
By Simmy in forum AWT / SwingReplies: 7Last Post: 08122007, 03:47 PM 
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04112007, 02:10 AM
Bookmarks