有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

将字符串转换为双精度时发生java错误?

我正在使用Jarowinkler方法编写一个程序来比较字符串。。。。。jaro-winkler方法根据字符串的相似性给出从0到1的值。我有两个巨大的数据库文件,一个用作参考,另一个用作数据库,其中包含重复项。通过使用引用文件,我需要从重复的数据库文件中找到原始数据。。。。以下是错误:::

Exception in thread "main" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Double.parseDouble(Unknown Source)
    at read.main(read.java:66)  

节目如下:

import java.util.*;
import java.io.*;
class read
{
public static void main(String args[]) throws IOException
{
    int countcolumns=0,countrows=0;
    JaroWinkler j=new JaroWinkler();
    quicksort e=new quicksort();
    PrintWriter out=new PrintWriter("res.txt");
    PrintWriter sort=new PrintWriter("sort.txt");
    PrintWriter fin=new PrintWriter("resultfinal.txt");
    double d=0;int i=0,l=0;
    int count=0;
    File f=new File("firstlistedited.txt");
    Scanner s=new Scanner(f);
    //File fil=new File("res.txt");
    //Scanner sca=new Scanner(fil); 
    double r[]=new double[100000];  
    String a,b,c;
    while(s.hasNext())
    {       
        a=s.nextLine();         
        File fi=new File("result.txt");
        Scanner sc=new Scanner(fi); 
        i=0;
        while(sc.hasNext())
        {           
            b =sc.nextLine();
             d=j.benzerlikOrani(a,b);                
            if(d>0.70)
            {                   
                r[i]=d;
                i++;
                //System.out.println("value on comparing "+a +" and "+b+" is "+d);  
                out.println(a+"/"+b+"="+d);
            }               
        }
        quicksort.quicksorts(r, 0, 99999);
        //System.out.println(a);
        //System.out.println("array is "+r[0]);
        sort.println("array is "+r[1]);
        sort.println("array is "+r[2]);

        sort.println("----------------");
        File fil=new File("res.txt");
        Scanner sca=new Scanner(fil);
        int count1=0;
        while(sca.hasNext())
        {

            count1++;

            c =sca.nextLine();
            String st="0.00",str="0.00";//,str1="",str2="";
            int num=c.length();
            for(int x=0;x<num;x++)
            {
                if(c.charAt(x)=='=')
                {
                    st=c.substring(x+1, num);
                    //System.out.println(c.substring(x+1, num));
                }
            }

//-------------------------------------------------------------------------------------

            //double dob=Double.valueOf(st.trim()).doubleValue();
            double dob=Double.parseDouble(st); //here is the error 

//-------------------------------------------------------------------------------------

            if(count1>=count)
            {
            if(r[0]==dob)
            {
                for(int x=0;x<num;x++)
                {
                    if(c.charAt(x)=='/')
                    {
                        str=c.substring(x+1, num);

                        //String str=c.substring(a.length(),num-a.length()+4);
                        System.out.println("comparing "+a+" with "+str);
                        fin.println("comparing "+a+" with "+str);
                    }
                }
            }
            }
        }
        count=count1;
        System.out.println("------------- ");   
    }       
    out.close();
    sort.close();
    fin.close();
}
}

非常感谢您的帮助


共 (1) 个答案

  1. # 1 楼答案

    在执行错误所在的行时,变量st包含一个空字符串。我认为当文件res.txt包含空行时会发生这种情况,但在其他情况下也可能发生这种情况。没有输入文件,我们无法复制它

    坦率地说,这种错误正是你在调试器中使用的错误(请求他人帮助之前)Learn to use one这对你将来会有很大帮助