Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java将csvLine.split字符串数组转换为浮点_Java_Android_Arrays_Csv - Fatal编程技术网

java将csvLine.split字符串数组转换为浮点

java将csvLine.split字符串数组转换为浮点,java,android,arrays,csv,Java,Android,Arrays,Csv,您好,我正在使用android studio进行拼贴工作,当我尝试使用csvLine.split String数组的两部分作为GPS坐标时,遇到了一个问题。我发现错误无法解析构造函数Geopoint(java.language.string,java.language.string) 我需要将ID[3]和ID[4]从字符串值转换为浮点值。谁能告诉我怎么做 int i = 0; BufferedReader reader = new BufferedReader(new Input

您好,我正在使用android studio进行拼贴工作,当我尝试使用csvLine.split String数组的两部分作为GPS坐标时,遇到了一个问题。我发现错误无法解析构造函数Geopoint(java.language.string,java.language.string)

我需要将ID[3]和ID[4]从字符串值转换为浮点值。谁能告诉我怎么做

    int i = 0;
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    try {
        String csvLine;
        while ((csvLine = reader.readLine()) != null) {
            ids=csvLine.split(",");
            try{
                Log.e("CSV file row "+ i, " "+ids[0] + ", " + ids[1]+ ", " + ids[2]+ ", " + ids[3]+ ", " + ids[4]) ;
                i++;

              //  GeoPoint csvGeoPoint = new GeoPoint(ids[3], ids[4]);  //The issue is here

              //  items = new ItemizedIconOverlay<>(this, new ArrayList<OverlayItem>(), markerGestureListener);
              //  OverlayItem you = new OverlayItem(ids[1], ids[2], (csvGeoPoint));
              //  items.addItem(you);
              //  mv.getOverlays().add(items);

            }
显示我的csv文件中的这四行。最后两个我将用于我的地质点,以便解释为什么它们是浮点数或双点数

E/CSV文件第0行:视图,酒店,大型酒店,50.9283421,-1.3928653 E/CSV文件第1行:TGI Fridays,餐厅,一个可爱的地方,50.9050199,-1.4133411 E/CSV文件第2行:Weather Spoons,酒吧,你的普通酒吧,50.9039012,-1.4078481 E/CSV文件第3行:大洋洲,俱乐部,一个巨大的俱乐部,50.9019739,-1.4161856

非常感谢您的支持:)

我需要将ID[3]和ID[4]从字符串值转换为浮点值 价值谁能告诉我怎么做

    int i = 0;
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    try {
        String csvLine;
        while ((csvLine = reader.readLine()) != null) {
            ids=csvLine.split(",");
            try{
                Log.e("CSV file row "+ i, " "+ids[0] + ", " + ids[1]+ ", " + ids[2]+ ", " + ids[3]+ ", " + ids[4]) ;
                i++;

              //  GeoPoint csvGeoPoint = new GeoPoint(ids[3], ids[4]);  //The issue is here

              //  items = new ItemizedIconOverlay<>(this, new ArrayList<OverlayItem>(), markerGestureListener);
              //  OverlayItem you = new OverlayItem(ids[1], ids[2], (csvGeoPoint));
              //  items.addItem(you);
              //  mv.getOverlays().add(items);

            }
只需这样做:

double num1 = Double.parseDouble(ids[3]);
double num2 = Double.parseDouble(ids[4]);
如果正如您所说,您的
地质点的构造函数需要两个双精度,那么这将是有效的

GeoPoint csvGeoPoint = new GeoPoint(num1, num2);